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