We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
至于为啥是==简单版==,复杂版的我不会啊:joy:
深拷贝 浅拷贝 赋值 的区别在哪?
赋的其实是该对象在栈中的地址,而不是堆中的数据
忘记在哪弄的图了,如果有谁看到麻烦评论下我补上
// target: 目标对象,被赋值的对象 function clone(target) { // 判断一下对象是不是引用类型(数组和对象) if (typeof target === 'object') { // 判断下 target 到底是数组还是对象,同时赋默认值 let cloneTarget = Array.isArray(target) ? [] : {}; // 循环遍历 target for (const key in target) { // 走递归函数 cloneTarget[key] = clone(target[key]); } // 返回 return cloneTarget; } else if(typeof target === 'function') { // 如果是 函数的话你懂得. return eval('(' + target.toString() + ')') } else { // 如果是基本类型的值直接 return return target; } }; var data = { name: '123', age: 15, data: { name: '大壮', age: 19 }, add: function() {} } console.log(clone(data)) /** { name: '123', age: 15, data: { name: '大壮', age: 19 }, add: [Function] } */
上面代码中,为了避免不理解,我直接截个图方便理解
好了.简单版就是这个样子.
复杂版的:
请慢慢食用,小心噎着(^▽^)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
至于为啥是==简单版==,复杂版的我不会啊:joy:
深拷贝 浅拷贝 赋值 的区别在哪?
赋的其实是该对象在栈中的地址,而不是堆中的数据
忘记在哪弄的图了,如果有谁看到麻烦评论下我补上
上面代码中,为了避免不理解,我直接截个图方便理解
好了.简单版就是这个样子.
复杂版的:
请慢慢食用,小心噎着(^▽^)
The text was updated successfully, but these errors were encountered: