封装的js代码进行复制对象

// 复制对象

export const deepCopy = (obj) =>{

let gettype=Object.prototype.toString

  if(typeof obj !='object' ||gettype.call(obj) ==='[object Date]'){

return obj;

}

if(Object.prototype.toString.call(obj) ==='[object Array]') {

return obj

}

let newobj = {};

for (let attr in obj) {

newobj[attr] =deepCopy(obj[attr]);

}

return newobj;

}

let obj1 = deepCopy (obj)

console.log(obj1)

你可能感兴趣的:(封装的js代码进行复制对象)