var SingletonFactory = (function(){
function SingletonClass() {
//do stuff
}
var instance;
return {
getInstance: function(){
if (instance == null) {
instance = new SingletonClass();
// Hide the constructor so the returned object can't be new'd...
instance.constructor = null;
}
return instance;
}
};
})();
var SingletonFactory = (function(){
function SingletonClass() {
//do stuff
}
var instance;
return {
getInstance: function(){
if (instance == null) {
instance = new SingletonClass();
// Hide the constructor so the returned object can't be new'd...
instance.constructor = null;
}
return instance;
}
};
})();
"use strict";
// require the events and the instance
const Events = require("events");
const events = new Events();
module.exports = events;
// Then require this instance in differnt file
// const events = require("./file-contain-the-singlton-class");
Code Example |
---|
:: |
:: jquery filtering |
Javascript :: |
:: |
:: |
Javascript :: How to add a class to html element js |
:: json vs xml |
Javascript :: |
:: |
Javascript :: |
:: |
:: salvar no localStorage react |
Javascript :: |
:: accordion reatjs |
Javascript :: |
:: |
:: jquery get second td of tr |
Javascript :: |
:: |
:: |
:: |
Javascript :: |
Javascript :: |
:: |
:: |
:: javascript window resize listener |
Javascript :: |
Javascript :: javascript run every 5 seconds |
:: nest js install and create project |
Javascript :: get current path nodejs |