# multiple-extend

> Multiple inheritance for Javascript ES6

Latest version **0.2.0** (published 2024-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install multiple-extend
pnpm add multiple-extend
yarn add multiple-extend
bun add multiple-extend
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2024-11-25 |
| First published | 2019-09-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 6.0 |
| Dependencies | 1 |
| Unpacked size | 7.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Panates Ltd. |
| Maintainers | erayhanoglu |
| Keywords | javascript, multiple, extend, inheritance |

## Links

- npm: https://www.npmjs.com/package/multiple-extend
- Repository: https://github.com/panates/multiple-extend
- Homepage: https://github.com/panates/multiple-extend#readme
- Issues: https://github.com/panates/multiple-extend/issues
- npm.io page: https://npm.io/package/multiple-extend

## Dependencies (1)

- [@jsopen/objects](https://npm.io/package/@jsopen/objects.md) ^1.4.2

## Recent versions

- 0.2.0 (latest) — 2024-11-25
- 0.1.3 — 2023-01-09
- 0.1.2 — 2019-12-30
- 0.1.1 — 2019-09-04
- 0.1.0 — 2019-09-03
- 0.0.1 — 2019-09-03

## README

# multiple-extend

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![Dependencies][dependencies-image]][dependencies-url]
[![DevDependencies][devdependencies-image]][devdependencies-url]

## About

This is a helper module for Javascript that allows multiple Classes inheritance. 

## Installation

`$ npm install multiple-extend [--save]`

## Usage

```js
const classes = require('multiple-extend');

class Character {
  constructor(name) {
    this.name = name;
    this.distance = 0;
    this.canWalk = true;
  }

  walk(x) {
    return this.distance += x;
  }
}

class Jumper {
  constructor() {
    this.distance = 0;
    this.canJump = true;
  }

  jump(x) {
    return this.distance += x;
  }
}

class Diver {
  constructor() {
    this.deep = 0;
    this.canDive = true;
  }

  dive(x) {
    return this.deep += x;
  }
}

class SuperCharacter extends classes(Character, Jumper, Diver) {
}

const player = new SuperCharacter('player1');
console.log(player.name); // Prints out "player1"

if (player.canWalk) // Can walk and will walk 5
  player.walk(5);

if (player.canJump) // Can jump and will jump 1
  player.jump(1);

if (player.canDive) // Can dive and will dive 1
  player.dive(1);
```

### Argument pass-through

You can also define which arguments will be sent to subclass constructors
````js
class SuperCharacter extends classes([Character, null], [Jumper, 1, 2], [Diver, [3, null]]) {
  constructor(distanceMin, distanceMax, ...args) {
    super(distanceMin, distanceMax, ...args);
    this.name = 'player1';
  }
}
````
In the example above Character constructor will be no argument, 
Jumper constructor will be called with arguments at index 1 and 2 (distanceMin, distanceMax),
Diver constructor will be called with arguments at index from 3 to Last.

### Checking implementations

You can check if extended class and its instance has implemented any class.

````js
const classes = require('multiple-extend');
const Implemented = classes.Implemented; // Special symb ol

class SuperCharacter extends classes(Character, Jumper, Diver) {
}

if (SuperCharacter[Implemented](Jumper))
  console.log('Jumper implemented');

// You can also check using class names
if (SuperCharacter[Implemented]('Diver'))
  console.log('Diver implemented');
````



## Node Compatibility

  - node `>= 6.0`;
  
### License
[MIT](LICENSE)

[npm-image]: https://img.shields.io/npm/v/multiple-extend.svg
[npm-url]: https://npmjs.org/package/multiple-extend
[travis-image]: https://img.shields.io/travis/panates/multiple-extend/master.svg
[travis-url]: https://travis-ci.org/panates/multiple-extend
[coveralls-image]: https://img.shields.io/coveralls/panates/multiple-extend/master.svg
[coveralls-url]: https://coveralls.io/r/panates/multiple-extend
[downloads-image]: https://img.shields.io/npm/dm/multiple-extend.svg
[downloads-url]: https://npmjs.org/package/multiple-extend
[gitter-image]: https://badges.gitter.im/panates/multiple-extend.svg
[gitter-url]: https://gitter.im/panates/multiple-extend?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[dependencies-image]: https://david-dm.org/panates/multiple-extend/status.svg
[dependencies-url]:https://david-dm.org/panates/multiple-extend
[devdependencies-image]: https://david-dm.org/panates/multiple-extend/dev-status.svg
[devdependencies-url]:https://david-dm.org/panates/multiple-extend?type=dev
[quality-image]: http://npm.packagequality.com/shield/multiple-extend.png
[quality-url]: http://packagequality.com/#?package=multiple-extend

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