function copy(obj) {
let result = Array.isArray(obj) ? [] : {};
Object.keys(obj).forEach(key => result[key] = obj[key]);
return result;
}
let newObj = {...obj}
Object.assign(newObj, obj)
function copy(obj) {
let result = Array.isArray(obj) ? [] : {};
Object.keys(obj).forEach(key => result[key] = obj[key]);
return result;
}
let newObj = {...obj}
Object.assign(newObj, obj)
本文标题:浅拷贝
本文链接:https://www.haomeiwen.com/subject/kbmhoktx.html
网友评论