singleton-mixin

    1.1.1 • Public • Published

    singleton-mixin

    npm version Build Status

    Attach singleton-pattern by Mix-in

    Installation

    npm install --save singleton-mixin
    

    Example

    var SingletonMixin = require('singleton-mixin');
    
    function Foo() {
    }
    
    // Or, Object.assign, lodash.assign, etc
    var objectAssign = require('object-assign');
    objectAssign(Foo, SingletonMixin);
    
    
    var foo = Foo.getInstance();
    var foo2 = Foo.getInstance();
    console.log(foo === foo2);  // -> true
    var foo3 = new Foo();
    console.log(foo === foo3);  // -> false
    
    Foo.clearInstance();
    
    var foo4 = Foo.getInstance();  // Created second instance
    console.log(foo4 === foo);  // -> false
    

    Install

    npm i singleton-mixin

    DownloadsWeekly Downloads

    1

    Version

    1.1.1

    License

    MIT

    Last publish

    Collaborators

    • kjirou