我最近開始對OOP javascript和一件事讀了,作者似乎跳過是當一個對象A已經宣佈,突然我看到「A.prototype.constructor = A; 例如,爲什麼OOP JavaScript中使用object.prototype.constructor?
var A = function(){}; // This is the constructor of "A"
A.prototype.constructor = A;
A.prototype.value = 1;
A.prototype.test = function() { alert(this.value); }
var a = new A(); // create an instance of A
alert(a.value); // => 1
所以我跑的螢火命令「變種A =函數(){};」。 ,然後「A.Constructor」揭示它是一個功能我明白這
我運行代碼「A.prototype。構造函數= A;「我認爲這將A構造函數從Function更改爲A.
A的構造函數屬性chan ged對不對?相反,當我運行「A.constructor」它仍然給我function()。
有什麼意義?
我也看到A.constructor.prototype.constructor.prototype ...到底是怎麼回事?
哪些作者,在哪裏? – 2012-01-31 05:04:47
我得到這個代碼是http://www.ruzee.com/blog/2008/12/javascript-inheritance-via-prototypes-and-closures – Matt 2012-02-01 03:00:01