1.原型链继承
function Super() {
this.name = "super";
}
function Sub() {}
Sub.prototype = new Super();
2.构造函数继承
function Super() {
this.name = "super";
}
function Sub() {
Super.call(this);
}
3.组合继承
function Super() {
this.name = "super";
}
function Sub() {
Super.call(this);
}
Sub.protptype = new Super();
Sub.protptype.constructor = Sub;
4.原型式继承
function create(o) {
function F() {};
F.prototype = o;
return new F();
}
5.寄生式继承
function create(o) {
function F() {};
F.prototype = o;
return new F();
}
function createSub(o) {
var clone = create(o);
clone.say = function() {};
return clone;
}
6.寄生组合式继承
function create(o) {
function F() {};
F.prototype = o;
return new F();
}
function createSub(sub, Super) {
var clone = create(Super.prototype);
clone.prototype.constructor =sub;
return clone;
}