@aminya/mixto

    1.0.0-aminya.1 • Public • Published

    Mixto: A simple mixin superclass Build Status

    npm install @aminya/mixto
    

    JavaScript Classes (ES6)

    To create a mixin, subclass mixto:

    const Mixin = require('mixto/lib/es6')
     
    class MyMixin extends Mixin {
      static classMethod() { console.log("foo"); }
      instanceMethod() { console.log("bar"); }
    }

    Then mix into classes with .includeInto:

    class MyClass {
      static initClass() {
        MyMixin.includeInto(this); // adds all the mixin's class properties or prototype properties to the target class if they aren't already defined
      }
    }
    MyClass.initClass();
     
    MyClass.classMethod();
    (new MyClass).instanceMethod();

    Or extend individual objects with .extend:

    const myObject = {a: 1, b: 2};
    MyMixin.extend(myObject);   // adds all the mixin's prototype properties to the target object if they aren't already defined
    myObject.instanceMethod();

    Or build standalone instances of your 'mixin':

    const standalone = new MyMixin;
    standalone.instanceMethod();

    CoffeeScript 1 Classes (ES5)

    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()

    Keywords

    Install

    npm i @aminya/mixto

    DownloadsWeekly Downloads

    4

    Version

    1.0.0-aminya.1

    License

    none

    Unpacked Size

    12.9 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar