Kris 69cf9a6c2a Missed syntax folders and moved samples out of tools | 4 tahun lalu | |
---|---|---|
.. | ||
lib | 4 tahun lalu | |
LICENSE.md | 4 tahun lalu | |
README.md | 4 tahun lalu | |
package.json | 4 tahun lalu |
To create a mixin, subclass mixto:
Mixin = require 'mixto'
class MyMixin extends Mixin
@classMethod: -> console.log("foo")
instanceMethod: -> console.log("bar")
Then mix into classes with .includeInto
:
class MyClass
MyMixin.includeInto(this)
MyClass.classMethod()
(new MyClass).instanceMethod()
Or extend individual objects with .extend
:
myObject = {a: 1, b: 2}
MyMixin.extend(myObject)
myObject.instanceMethod()
Or build standalone instances of your 'mixin':
standalone = new MyMixin
standalone.instanceMethod()