题解 | #深拷贝#

深拷贝

https://www.nowcoder.com/practice/70ca77b52d424ced8ebb348cd77c1dc5

{"html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _completeDeepClone = (target, map = new WeakMap()) => {\n                // 补全代码\n                if(typeof target !== 'object' || target === null) {\n                    return target\n                }\n                if(map.has(target)) {\n                    return map.get(target)\n                }\n                const result = new target.constructor()\n                map.set(target,result)\n                for(let key in target) {\n                    if(Object.prototype.hasOwnProperty.call(target, key)) {\n                        result[key] = _completeDeepClone(target[key],map)\n                    }\n                }\n                return result\n            }\n        </script>\n    </body>\n</html>","css":"","js":""}

全部评论

相关推荐

点赞 评论 收藏
分享
求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务