摘要: 1 //寄生组合式继承 2 function object(o) { 3 function F() {} 4 F.prototype = o; 5 return new F(); 6 } 7 8 function inheritPrototype(subType, superType) { 9 var prototype = object(superType.prototype);10 prototype.constructor = subType;11 subType.prototype = prototype;12 }13 14 func... 阅读全文
posted @ 2012-04-30 11:36 小猩猩君 阅读(718) 评论(0) 推荐(0) 编辑
摘要: 1 //组合继承是Javascript最常用的继承模式 2 function SuperType(name) { 3 this.name = name; 4 this.colors = ["red", "blue", "green"]; 5 } 6 7 SuperType.prototype.sayName = function() { 8 console.log(this.name); 9 };10 11 function SubType(name, age) {12 //继承属性13 SuperType.call(this, na 阅读全文
posted @ 2012-04-30 11:35 小猩猩君 阅读(226) 评论(0) 推荐(0) 编辑