Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ampersand-class-extend

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-class-extend

JS class extension tool for enabling easily extending prototype with multiple objects.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-61.23%
Maintainers
4
Weekly downloads
 
Created
Source

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.

browser support

browser support

install

npm install ampersand-class-extend

usage

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.

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

Keywords

FAQs

Package last updated on 31 Mar 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc