浅拷贝

作者: bestCindy | 来源:发表于2020-12-30 17:48 被阅读0次
    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