guyuezhai / interviewSummary

some summary of interview
0 stars 0 forks source link

写出以下代码打印结果 #15

Open guyuezhai opened 4 years ago

guyuezhai commented 4 years ago
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);
guyuezhai commented 4 years ago
// webSite 引用地址 赋值给了o
function changeObjProperty(o) {
  //改变对应地址内对象属性值
  o.siteUrl = "http://www.baidu.com"
  // 变量o指向新的地址 以后的变动和旧址无关
  o = new Object()
  o.siteUrl = "http://www.google.com"
  o.name='google'
} 
let webSite = new Object();
changeObjProperty(webSite);
console.log(webSite); // =>  {siteUrl: "http://www.baidu.com"}