读书笔记-JavaScript高级程序设计(1)
1.组合继承 (JavaScript中最常用的继承模式 ) (position: page168) (书中定义了两个变量名SuperType SubType 乍一看 感觉不太能区分,我将改为 a b ,更加明显区分开来这是两个东西。) function a(name){ this.name = name; this.colors = ["red", "blue", "green"]; } a.prototype.sayName = function(){ alert(this.name);} function b(name, age){ //继承属性 a.call(this, name); this.age = age; } //继承方法 b.prototype = new a(); b.prototype.constructor = b; b.prototype.sayAge = function(){ alert(this.age); }; var instance1 = new b("Nicholas", 29); instance1.colors.push("black");...