Skip to content
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

不能处理循环引用 #1

Open
zgw010 opened this issue Mar 27, 2019 · 2 comments
Open

不能处理循环引用 #1

zgw010 opened this issue Mar 27, 2019 · 2 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@zgw010
Copy link

zgw010 commented Mar 27, 2019

问题是什么

不能处理循环引用

环境

  • 浏览器:chrome 73.0.3683.75

在线例子

// case 1, 自身有环
const obj = {
  foo: {
    bar:null
  }
}
obj.foo.bar = obj.foo 
// case 2, 互相引用
const obj1 = {
  foo: {
    bar:null
  }
}
const obj2 = {
  baa: {
    caa:obj1.foo
  }
}
obj1.foo.bar = obj2.baa
extend(true, obj1,obj2);

其他

我试了下 jquery 也不能处理这种, 看了下他源码, 处理的方式和你是一样的, 能解释下为什么要这么处理吗,如果真有循环引用的话, 会一直不能 return target ,那么这个判断条件就一直是 false 呀.

@yanhaijing
Copy link
Member

yanhaijing commented Mar 27, 2019

这个代码就是从jq copy来的,😶
这种实现方式可以支持一层的循环引用,如果层级深就不行了

@yanhaijing yanhaijing self-assigned this Mar 27, 2019
@yanhaijing yanhaijing added the help wanted Extra attention is needed label Mar 27, 2019
@yanhaijing
Copy link
Member

@hasaki1997 可以思考思考如何显示,争取提个pr,✧(≖ ◡ ≖✿)嘿嘿

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants