ampersand-class-extend
Helper function for setting up prototype chains for subclasses.
Largely copied out of Backbone, but modified to enable extending a prototype with multiple mixins at once.
install
npm install ampersand-class-extend
usage
Your base object module might look something like this:
var extend = require('ampersand-class-extend');
function YourConstructor() {}
YourConstructor.extend = extend;
module.exports = YourConstructor;
Then in a file using said constructor:
var YourConstructor = require('./your-constructor');
var mixinMethods = require('some-other-methods');
var otherMixinMethods = require('even-more-methods');
module.exports = YourConstructor.extend(mixinMethods, otherMixinMethods, {
yetAnotherMethod: function () {
}
});
Now, when creating instances of the subclass, they'll have all the mixins while still passing instanceof
checks for both the parent and the subclass.
credit
Most of the credit goes to Jeremy Ashkenas and the other authors of Backbone.js.
Modified to be standalone Common JS and to allow you to pass multiple extend objects by @HenrikJoreteg.
license
MIT