“objeto clon de typescript” Código de respuesta

Objeto clon en TypeScript

//1.Shallow copy:
let Copy = {...yourObject}
//2.Deep Copy: a. through recusive typing functionality:
let Cone = DeepCopy(yourObject);
public DeepCopy(object: any): any
{
  if(object === null)
  {
    return null;
  }
  const returnObj = {};
  Object.entries(object).forEach(
  ([key, value]) =>{
    const objType = typeof value
  if(objType !== "object" || value === null){
     returnObj[key] = value;
  }
  else{
  	returnObj[key] = DeepCopy(value);
  }
}
//b.Hardway: repeat the following expanstions for all complex types as deep as you need
let Copy = {...yourObject, yourObjsComplexProp: {...yourObject.yourObjsComplexProp}}
TheCodeTrooper

objeto clon de typescript

import _ from "lodash"

const obj = { foo: "bar" }
const clone = _.cloneDeep(obj);
Jens

Respuestas similares a “objeto clon de typescript”

Preguntas similares a “objeto clon de typescript”

Más respuestas relacionadas con “objeto clon de typescript” en TypeScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código