class NewObj {
arrOriginObj:Object[]=[];
arrNewObj:Object[]=[];
clone(objP:Object){
for(let i=0; i< this.arrOriginObj.length;i++){
if(objP===this.arrOriginObj[i])
return this.arrNewObj[i];
}
let newObj={};
this.arrNewObj.push(newObj);
this.arrOriginObj.push(objP);
for(let key in objP){
if(objP.hasOwnProperty(key)) {
if(objP[key] !== null && typeof(objP[key]) === "object" ) {
newObj[key] = this.clone( objP[key] );
}else
newObj[key] = objP[key];
}
}
return newObj;
}
} |