🚀 DAY 4 OF LAUNCH WEEK: Introducing GitHub Actions Scanning Support.Learn more →
Socket
Book a DemoInstallSign in
Socket

singletone

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

singletone

Powerful JavaScript singleton design pattern implementation

latest
Source
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

Build Status

Singletone

Powerful and easy to use JavaScript implementation of the Singleton design pattern. It creates singleton instance which nobody can to change or replace. Now it supports Node.js (CommonJS modules) only, but frontend support needed (AMD, etc.). Help wanted.

Install

npm i --save singletone

Examples

var singletone = require('singletone');

function Player() {
  // save the instance local variable for the moment
  var singletonInstance = singletone(this);

  // rewrite our singleton constructor
  Player = singletonInstance.constructor;

  // add some instance properties
  this.status = "stopped";

  // return singleton instance
  return singletonInstance;
}

Player.prototype.play = function () {
  this.status = "playing";
};

Player.prototype.stop = function () {
  this.status = "stopped";
};

var player = new Player();

player.play();

console.log(player.status);
// "playing"

var player2 = Player();

console.log(player2.status);
// "playing"

For more information and examples look at the tests.

Contribution

If you want to send some PR, checkout develop branch please. It contains the latest commits.

Keywords

singleton

FAQs

Package last updated on 14 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts