singleton-class-extended
Singleton pattern enforcing a single instance with a getter
Last updated 3 years ago by garrylachman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install singleton-class-extended 
SYNC missed versions from official npm registry.

Singleton Class Extended

Based on singleton-class. The main change is remove the class initialize (new MyClass). The instance created on first `instance` getter call. The constructor logic moved to __initialize method.

Only allows one instance of the singleton to be created

Usage

  • npm install --save singleton-class-extended
  • Extend the Singleton class with your own
const Singleton = require('singleton-class-extended');

class MyClass extends Singleton {
  __initialize(){
    // Use this method as constructor
    this.name = 'bob';
    // Do other things
  }
}

console.log(MyClass.instance.name);

Current Tags

  • 1.0.6                                ...           latest (3 years ago)

2 Versions

  • 1.0.6                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (6)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org | Home |