1.0.4 • Published 7 years ago

the-mixture v1.0.4

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

Mixture Logo

Mixture is a simple and easy to use tool for creating your own javascript mixins.

npm i -s the-mixture

Usage

Just create a class that extends Mixture, define all your cool methods there and run YourMixin.mixTo(yourObject).
You also can define a method with the same name as your mixin class to initialize needed properties.

Example:

const Mixture = require('the-mixture')

class MyCoolMixin extends Mixture {
  myCoolMixinMethod () {
    return 'Hey, ' + this.name + '! It looks good.'
  }

  MyCoolMixin () {
    this.name = this.name || 'Alice'
    console.log('My cool mixin has been mixed to ' + this.name + '!')
  }
}

class MyCoolClass {
  constructor () {
    this.name = 'Ecila'
    MyCoolMixin.mixTo(this)
  }
}

let myCoolObject = new MyCoolClass()
console.log(myCoolObject.myCoolMixinMethod())

let myAnotherCoolObject = {}
MyCoolMixin.mixTo(myAnotherCoolObject)
console.log(myAnotherCoolObject.myCoolMixinMethod())

Output:

My cool mixin has been mixed to Ecila!
Hey, Ecila! It looks good.
My cool mixin has been mixed to Alice!
Hey, Alice! It looks good.

License

Mixture is licensed under MIT, see LICENSE.md for details

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago