Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
ampersand-class-extend
Advanced tools
JS class extension tool for enabling easily extending prototype with multiple objects.
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.
npm install ampersand-class-extend
Your base object module might look something like this:
var extend = require('ampersand-class-extend');
// your base object
function YourConstructor() {}
// simply attach it directly to the object constructor
YourConstructor.extend = extend;
// export it
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');
// Nowe we add some more stuff and export a modified constructor
// (we can pass in as many other objects containing methods as we want).
module.exports = YourConstructor.extend(mixinMethods, otherMixinMethods, {
yetAnotherMethod: function () {
// do something
}
});
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.
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.
MIT
FAQs
JS class extension tool for enabling easily extending prototype with multiple objects.
The npm package ampersand-class-extend receives a total of 31,149 weekly downloads. As such, ampersand-class-extend popularity was classified as popular.
We found that ampersand-class-extend demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.