# create-mixin

> Mix the prototype of one class into another

Latest version **3.0.0** (published 2019-11-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install create-mixin
pnpm add create-mixin
yarn add create-mixin
bun add create-mixin
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2019-11-15 |
| First published | 2018-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Lloyd Brookes |
| Maintainers | 75lb |
| Keywords | create, mixin, class, extends, es2015, es6 |

## Links

- npm: https://www.npmjs.com/package/create-mixin
- Repository: https://github.com/75lb/create-mixin
- Homepage: https://github.com/75lb/create-mixin#readme
- Issues: https://github.com/75lb/create-mixin/issues
- npm.io page: https://npm.io/package/create-mixin

## Recent versions

- 3.0.0 (latest) — 2019-11-15
- 2.0.1 — 2019-05-27
- 2.0.0 — 2019-05-27
- 1.1.1 — 2018-12-22
- 1.1.0 — 2018-12-19
- 1.0.0 — 2018-05-29

## README

[![view on npm](https://img.shields.io/npm/v/create-mixin.svg)](https://www.npmjs.org/package/create-mixin)
[![npm module downloads](https://img.shields.io/npm/dt/create-mixin.svg)](https://www.npmjs.org/package/create-mixin)
[![Build Status](https://travis-ci.org/75lb/create-mixin.svg?branch=master)](https://travis-ci.org/75lb/create-mixin)
[![Dependency Status](https://badgen.net/david/dep/75lb/create-mixin)](https://david-dm.org/75lb/create-mixin)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)

# create-mixin

Useful for achieving something resembling multiple-inheritence in Javascript.

```js
const mixInto = require('create-mixin')
const EventEmitter = require('events')

class EmittingArray extends mixInto(EventEmitter)(Array) {}
```

## Example

Given these two classes.


```js
class Base {
  constructor () {
    this.ranBaseConstructor = true
  }
  baseMethod () {
    return 1
  }
}

class Mixin {
  constructor () {
    this.ranMixinConstructor = true
  }
  someMethod () {
    return 2
  }
}
```

Create a new class mixing one class into another.

```js
> const mixInto = require('create-mixin')

> class Something extends mixInto(Mixin)(Base) {}
```

Behaviour of new class.

```js
> const something = new Something()

> /* new class has methods of both source classes */
> something.baseMethod()
1

> something.someMethod()
2

> /* Only the base constructor is run */
> something.ranBaseConstructor
true

> something.ranMixinConstructor
undefined

> something instanceof Base
true

> something instanceof Mixin
false
```

* * *

&copy; 2018-19 Lloyd Brookes \<75pound@gmail.com\>.

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