@lexi.ch home, code, stuff

Reminder: Basic prototypal inheritance in JavaScript 14.02.2014

// ---------- Parent "Class" ---------
var MyClass = function(paramA) {
    this.paramA = paramA;
};
MyClass.prototype.getA = function() {
    return this.paramA;
}

var obj = new MyClass(5);
console.log(obj.paramA);

// -------- Inherited "Class" -----------
var MyChildClass = function(paramA,paramB) {
    this.base = MyClass;
    this.base(paramA);
    this.paramB = paramB;
};
MyChildClass.prototype = new MyClass();
MyChildClass.prototype.getB = function() {
    return this.paramB;
}

var b = new MyChildClass(6,'gugus');
console.log(b.paramA, b.paramB);