JS对象深拷贝

        // 对象深拷贝(数组和对象)
        function deepClone(resource) {
            if (Array.isArray(resource)) {
                let dest = []
                let length = resource.length
                while (length--) {
                    console.log(length)
                    dest[length] = deepClone(resource[length])
                }
                return dest
            } else if (typeof resource === 'object') {
                let dest = {}
                for (let key in resource) {
                    if (resource.hasOwnProperty(key)) {
                        dest[key] = deepClone(resource[key])
                    }
                }
                return dest
            }
            return resource
        }

https://www.cnblogs.com/dabingqi/p/8502932.html

posted @ 2018-03-27 19:33  樱风凛  阅读(137)  评论(0编辑  收藏  举报