array inheritance question in javascript
function ClassA() { this.a=[]; this.aa=100; }
function ClassB() { }
ClassB.prototype = new Clas开发者_如何学JAVAsA;
ClassB.prototype.b=function(){return "classbb"};
for (var l in ClassB.prototype){
Array.prototype[l] = ClassB.prototype[l];
}
var array1 = [];
alert(array1.b());
Can
Array.prototype[l] = ClassB.prototype[l]
be replaced by
Array.prototype[l] = ClassB[l]
? Could someone help me? Thanks.
No, you can't.ClassB has no property b, ClassB.prototype has.
If you do, in alert(array1.b()); array1.b will be undefined
加载中,请稍侯......
精彩评论