Solution 1:
var Singleton = (function () {
var instance;
function init() {
return {
method: function () { console.log('hello world'); },
property: {}
};
}
return {
getInstance: function () {
getInstance: function () {
if (!instance) { instance = init();
}
return instance;
}
}; })();
Solution 2:
function Singleton()
function Singleton()
{
this.instance = null;
this.field = {};
}
Singleton.getInstance = function ()
{
if (!this.pInstance)
{
this.instance = new Singleton();
}
return this.instance;
};
No comments:
Post a Comment