Skip to content

Dexie.derive()

David Fahlander edited this page May 6, 2014 · 6 revisions

Fixes the prototype chain for OOP inheritance.

Sample

function Vehicle () {
}

Vehicle.prototype.move = function() {
    throw new Error ("Don't know how to move");
}

function Car() {
}

Dexie.derive(Car).from(Vehicle).extend(function() {
    //
    // Private closure scope for private methods
    //
    function privFunc() {
        alert ("The wheels are rolling");
    }

    return {
        //
        //  Public methods here (all methods are put on Car.prototype)
        //

        move: function() {
            privFunc();
        }
    }
});

var car = new Car();
alert (car instanceof Vehicle);// alerts 'true'
car.move();
Clone this wiki locally