【发布时间】:2012-02-22 21:04:03
【问题描述】:
我最近开始阅读 OOP javascript,作者似乎跳过的一件事是,当对象 A 被声明时,我突然看到“A.prototype.constructor =A; 例如,
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
所以我在 firebug "var A = function(){};" 中运行命令
然后是“A.Constructor”,它揭示了它是一个函数。我明白这一点。
我运行代码“A.prototype.constructor = A;”我认为这会将 A 构造函数从 Function 更改为 A。
A 的构造函数属性已经改变了吧?相反,当我运行“A.constructor”时,它仍然给我函数()。
有什么意义?
我也看到了 A.constructor.prototype.constructor.prototype.. 这是怎么回事?
【问题讨论】:
-
哪些作者,在哪里?
-
我得到这个的代码是ruzee.com/blog/2008/12/…
标签: javascript oop