我所理解的 new Constructor();
在 js 裡面要模擬 classical 的方式 產生物件的方式就是用 new 加上函式 當成建構子。
以我目前的理解,內部可能是這樣運作的:
var n = function(construct,args) {
var o = new Object();
o.prototype = construct;
construct.apply(o,args);
return o;
}
var test = n((function(a) { this.a = a}),[1]);
alert(test.a);// 1
n 函式 模擬 new 的動作,第一個函式為建構子,第二個函數為參數陣列,
進入以後則模擬物件呼叫建構子,並將物件當成 this 傳入,最後將產生的物件回傳。