I do not know how a singleton has functionality in a class
I have tried its function and its state but it still doesn't execute the program for me if I do so.
I do not know how a singleton has functionality in a class
I have tried its function and its state but it still doesn't execute the program for me if I do so.
Here is an example of singleton using a factory:
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 reset
instance.constructor = null;
}
return instance;
}
};
})();
// ...
var test = SingletonFactory.getInstance();
More information available here.