Parasitic + Combination Inheritance
Blogs20132013-10-22
JavaScript: Parasitic + Combination Inheritance
The Parasitic + Combination Inheritance which I use in my codes:
//Parasitic + Combination Inheritance
// reference:
function object(o) {
function F(){}
F.prototype = o;
return new F();
}
// deal with prototype:
function inheritPrototype(child, parent) {
function F() {}
F.prototype = parent.prototype;
var p = new F();
p.constructor = child;
child.prototype = p;
}
function Super(args) {
//this attrs and methods
}
Super.prototype.say1 = function() {
//process args...
}
function Sub(args, more_args) {
//inherit Super
//2.
Super.call(this, args);
this.more_arges = more_args;
}
//1.
inheritPrototype(Sub, Super);
Sub.prototype.say2 = function() {
// process more_args;
}These are original from Nicholas Zakasās āProfessional JavaScript for Web Developers (3rd Edition)ā which I refer to.
