摘要: //借用构造函数(constructor stealing),有时候也叫伪造对象或者经典继承//弊端:原型方法不可复用,只有构造函数的属性可以复用function SuperType() { this.colors = ["red", "blue"];}function SubType() { SuperType.call(this); //SuperType.apply(this);}var instance1 = new SubType();instance1.colors.push("black");console.log(in 阅读全文
posted @ 2013-07-06 15:56 金帛 阅读(170) 评论(0) 推荐(0)
摘要: function SuperType() { this.property = true;}SuperType.prototype.getSuperValue = function () { return this.property;}function SubType() { this.subproperty = false;}//继承了SuperTypeSubType.prototype = new SuperType();SubType.prototype.getSubValue = function () { return this. subproperty;}va... 阅读全文
posted @ 2013-07-06 15:40 金帛 阅读(213) 评论(0) 推荐(0)