时间:2021-07-01 10:21:17 帮助过:4人阅读
es5的写法
function clone(obj) {
if(obj == null) return null;
let newObj = obj instanceof Array ? [] : {};
for(var i in obj) {
newObj[i] = typeof obj[i] == "object" ? clone(obj[i]) : obj[i];
}
return newObj;
}es6的写法
const clone2 = (obj) => {
let proto = Object.getPrototypeOf(obj);
return Object.assign({}, Object.create(proto), obj)
}相关推荐:
js实现深分享
以上就是js实现深度的详细内容,更多请关注Gxl网其它相关文章!