Skip to content

Instantly share code, notes, and snippets.

View dsxsxsxs's full-sized avatar

dsxs dsxsxsxs

View GitHub Profile
@dsxsxsxs
dsxsxsxs / singleton.js
Created September 14, 2017 05:44
Singleton pattern with JS ES5 and ES6
function Singleton() {
if (!(this instanceof Singleton))
return new Singleton;
if (Singleton.hasOwnProperty('singleton'))
return Singleton.singleton;
Object.defineProperty(Singleton, 'singleton',{
value: this,
enumerable:false,
writable:false,
configurable:false