Basically, you create a temporary function that does nothing, you install your prototype, has a prototype of the parent class, then you can use the base class as the parent without calling its constructor.
If you need to reference the constructor of the parent class from the constructor of the child class, you must use Function.prototype.apply to redirect the constructor call.
Javascript inheritance model:
// Base class var Base = function ( ) { this.foo = 40; }; Base.prototype.bar = function ( ) { return this.foo; }; // Inherited class var Child = function ( ) { Base.apply( this, arguments ); this.foo += 2; }; var F = function ( ) { }; F.prototype = Base.prototype; Child.prototype = new F( );
source share