https://github.com/kjirou/singleton-mixin
Attach singleton-pattern by Mix-in
https://github.com/kjirou/singleton-mixin
Last synced: 3 months ago
JSON representation
Attach singleton-pattern by Mix-in
- Host: GitHub
- URL: https://github.com/kjirou/singleton-mixin
- Owner: kjirou
- Created: 2015-09-06T14:19:28.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2021-08-31T07:08:01.000Z (almost 4 years ago)
- Last Synced: 2025-03-29T04:14:29.167Z (4 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# singleton-mixin
[](http://badge.fury.io/js/singleton-mixin)
[](https://travis-ci.org/kjirou/singleton-mixin)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); // -> falseFoo.clearInstance();
var foo4 = Foo.getInstance(); // Created second instance
console.log(foo4 === foo); // -> false
```