創(chuàng)建空對(duì)象;
var obj = {};設(shè)置新對(duì)象的constructor屬性為構(gòu)造函數(shù)的名稱,設(shè)置新對(duì)象的proto屬性指向構(gòu)造函數(shù)的prototype對(duì)象;
obj.proto = ClassA.prototype;
擴(kuò)展了新對(duì)象的原型鏈。使用新對(duì)象調(diào)用函數(shù),函數(shù)中的this被指向新實(shí)例對(duì)象:
ClassA.call(obj); //{}.構(gòu)造函數(shù)();
4.返回this指針。當(dāng)存在顯示的返回時(shí),返回return后面的內(nèi)容。新建的空對(duì)象作廢。
function test() {
this.name = "test";
}
test.prototype = {
a:{},
b:{}
}
var c = new test();