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
上期 #155 讲了js 深拷贝的简单实现方法,还留了个尾巴,没有解决对象重复引用的问题
例子1:
var obj={ a:1 } obj.b=obj
例子2:
o1={a:1};o2={a:o1};o3={a:o2};o1.a=o3 }
这时去做深拷贝,会陷入无限递归。
对象本身就是树形结构,可以用一个数组来保存当前枝叶链上的所有object,如果下层枝叶又引用上层的obj,那就直接赋值,而不是采用递归,从而打破无限递归的深渊。
【具体实现代码】
The text was updated successfully, but these errors were encountered:
No branches or pull requests
重复引用会有什么问题
例子1:
例子2:
这时去做深拷贝,会陷入无限递归。
怎么解决
对象本身就是树形结构,可以用一个数组来保存当前枝叶链上的所有object,如果下层枝叶又引用上层的obj,那就直接赋值,而不是采用递归,从而打破无限递归的深渊。
【具体实现代码】
The text was updated successfully, but these errors were encountered: