# ampersand-class-extend

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

Latest version **2.0.0** (published 2016-05-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install ampersand-class-extend
pnpm add ampersand-class-extend
yarn add ampersand-class-extend
bun add ampersand-class-extend
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-05-25 |
| First published | 2014-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Henrik Joreteg |
| Maintainers | fyockm, gar, henrikjoreteg, latentflip, lukekarrys, pgilad |
| Keywords | ampersand, inheritance, class |

## Links

- npm: https://www.npmjs.com/package/ampersand-class-extend
- Repository: https://github.com/ampersandjs/ampersand-class-extend
- Issues: https://github.com/ampersandjs/ampersand-class-extend/issues
- npm.io page: https://npm.io/package/ampersand-class-extend

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.11.1

## Recent versions

- 2.0.0 (latest) — 2016-05-25
- 1.0.2 — 2015-03-31
- 1.0.1 — 2014-09-04
- 1.0.0 — 2014-04-10
- 0.1.4 — 2014-03-31
- 0.1.3 — 2014-03-22
- 0.1.2 — 2014-03-22
- 0.1.1 — 2014-03-17

## README

# 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:

```javascript
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:

```javascript
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](http://twitter.com/henrikjoreteg).


## license

MIT

---
_Source: https://npm.io/package/ampersand-class-extend · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
