经典继承就是组合继承,就是组合构造函数和原型链的优点混合继承。
1.避免引用类型的属性初始化
2.避免相同方法的多次初始化
function Super(name){ this.ages = [100,200,300]; this.name = name; } Super.prototype.print = function(){ console.log(this.ages); } function Sub(name){ Super.call(this,name); } Sub.prototype = new Super(); Sub.prototype.getName = function(){ console.log("getName"); } var subobj = new Sub('subobj');