Socket
Socket
Sign inDemoInstall

create-mixin

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-mixin

Mix the prototype of one class into another


Version published
Weekly downloads
94K
decreased by-1.96%
Maintainers
1
Weekly downloads
 
Created
Source

view on npm npm module downloads Build Status Dependency Status js-standard-style

create-mixin

Useful for achieving something resembling multiple-inheritence in Javascript.

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

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

Example

Given these two classes.

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.

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

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

Behaviour of new class.

> 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

© 2018-19 Lloyd Brookes <75pound@gmail.com>.

Keywords

FAQs

Package last updated on 15 Nov 2019

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