Singleton in javascript
Fri Jun 17 2022 16:46:59 GMT+0000 (Coordinated Universal Time)
Saved by
@soyreynald
#javascript
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;
}
};
})();
content_copyCOPY
This is a nice sample of how to implement the Singleton design pattern in javascript.
https://www.google.com/search?q=Singleton in javascript
Comments