sayid760/Notes

【计算题】实例、指针类

Opened this issue · 0 comments

1、

function Foo() {
    Foo.a = function() {
        console.log(1)
    }
    this.a = function() {
        console.log(2)
    }
}
Foo.prototype.a = function() {
    console.log(3)
}
Foo.a = function() {
    console.log(4)
}
Foo.a();
let obj = new Foo();
obj.a();
Foo.a();
4 2 1

2、

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

考察对象引用类型。 webSite是一个指针,指向堆内存里的某一具体地址, o.siteUrl = "http://www.baidu.com", 即这个具体地址里多了个属性。 o = new Object(), 现在o指针指向了另外一个堆地址,跟刚才那个完全不在一个位置。

3、
4、