Javascript Inheritance

Inheritance in Javascript is pretty simple.


function Child(arg1, arg2)
{
    Parent.apply(this, arguments);
    // .. other methods
}

The apply function calls the Parent function with arguments and sets this to Child’s this object. The arguments variable contains all the arguments passed to Child. (Available since Javascript 1.2).

To create an instance of Child call:


    var instance = new Child(x, y);

Leave a Reply

You must be logged in to post a comment.