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

写出如下代码的打印结果 #536

Open
Rashomon511 opened this issue Jul 4, 2019 · 0 comments
Open

写出如下代码的打印结果 #536

Rashomon511 opened this issue Jul 4, 2019 · 0 comments

Comments

@Rashomon511
Copy link
Owner

function changeObjProperty(o) {
  o.siteUrl = "http://www.baidu.com"
  o = new Object()
  o.siteUrl = "http://www.google.com"
} 
let webSite = new Object();
changeObjProperty(webSite);
console.log(webSite.siteUrl);

http://www.baidu.com
原因:函数的形参是值传递的,形参 o 的指向发生改变,指向堆内存中一个新的对象

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