-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
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
如何实现一个稳定的深拷贝? #4
Comments
这种方式实现可以满足基本9成以上的对象拷贝。但是却无法处理带有循环引用的对象,例如
上面的方式考虑到了数组的数组以及值为null时的情况。而且通过使用一个WeakMap来解决了循环引用的问题。但是这种方式的缺点就是对象层级较深的情况下,同样的会由于递归造成递归爆栈的问题。而且,这种方式使用了WeakMap,对ES5的兼容性也不佳。
以上便是常用的几种深拷贝的实现方式,各有特点,需要根据不同的需要选择不同的实现方式。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
深拷贝在日常编码中经常用到,用哪种方式实现的深拷贝最为稳定呢?
The text was updated successfully, but these errors were encountered: