5
后,我发现这个有趣的问题:保持正确构造继承
function a() { this.aprop = 1; }
function b() { this.bprop = 2; }
b.prototype = new a(); // b inherits from a
var x = new b(); // create new object with the b constructor
assert(x.constructor == b); // false
assert(x.constructor == a); // true
据我所知,x.constructor
应b
,但它实际上是a
当从a
通过其原型b
继承?有没有一种方法,我可以从a
继承而不用搞砸我的构造函数?
谢谢!对于我来说写一个能够完成这两行的快速`函数(目标,父)`是一个好主意吗? – 2010-12-23 11:23:45