jsFiddle Demo
A couple of things. extend really just adds properties; it does little. So you need to have a function for your class ready to inherit from the base class, and then use the extension for this class prototype.
function MyChildClass(){}; MyChildClass.prototype = new MyBaseClass(); $.extend(MyChildClass.prototype, { init: function() { MyBaseClass.prototype.init(); console.log('I am initializing the child class'); } });
Here is another approach I would like to use for inheritance - when the specifics of the methods will be a problem - this is saving the base class in its own property
function MyChildClass(){}; MyChildClass.prototype = new MyBaseClass(); MyChildClass.prototype.base = new MyBaseClass(); $.extend(MyChildClass.prototype, { init: function() { this.base.init(); console.log('I am initializing the child class'); } });
Travis j
source share