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

在浏览器中,对象属性的赋值操作会先于变量赋值操作执行 #40

Open
zuopf769 opened this issue May 9, 2023 · 1 comment

Comments

@zuopf769
Copy link

zuopf769 commented May 9, 2023

var a = { n: 1 }
var b = a;
a.x = (a = { n: 2 })
console.log(a.n, b.n)
console.log(a.x, b.x)
@zuopf769
Copy link
Author

zuopf769 commented May 9, 2023

核心:
为在浏览器中,对象属性的赋值操作会先于变量赋值操作执行。因此,执行 a.x = (a = { n: 2 }) 时,会先将 a 的属性 x 赋值为 undefined,然后再将 a 的值更新为 { n: 2 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant