Simple 'extend' helper for inheritance and subclassing
npm install simpler-extendSimple 'extend' helper for inheritance and subclassing. Adapted from Backbone.js's [Model.extend] and CoffeeScript. This works like simple-extend, except this does not have any dependencies.

Assign it to your base class's .extend:
``js`
function Shape() { ... }
Shape.extend = require('simpler-extend');
Then use it to subclass:
`js`
var Circle = Shape.extend({
getArea: function () {
return this.width * this.height;
}
});
You can also add a constructor as constructor:
`js`
var Circle = Shape.extend({
constructor: function () { ... }
});
Calling methods from the base class:
`js``
var Circle = Shape.extend({
getArea: function () {
var super = Shape.prototype.getArea.apply(this, arguments);
return super * Math.PI;
}
});
See Backbone.js's [Model.extend] documentation for more details.
simpler-extend © 2015+, Rico Sta. Cruz. Released under the [MIT] License.
Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]).
> ricostacruz.com ·
> GitHub @rstacruz ·
> Twitter @rstacruz
[MIT]: http://mit-license.org/
[contributors]: http://github.com/rstacruz/simpler-extend/contributors
[Model.extend]: http://backbonejs.org/#Model-extend