Skip to content

Instantly share code, notes, and snippets.

@crongro
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crongro/8934987 to your computer and use it in GitHub Desktop.
Save crongro/8934987 to your computer and use it in GitHub Desktop.
singleton pattern by codepen
var obj = (function() {
var middle;
var _name = "jisu";
function _getName() {
return _name;
}
function _setName(_rename) {
return _name = _rename;
}
function exportFun() {
var _ran = Math.random();
return {
getName : _getName,
setName : _setName,
ran : _ran
}
}
return {
proxyFun : function() {
//if(middle) return middle; //result : true;
//else return middle = exportFun();
return middle = exportFun(); //result : false;
}
}
})();
console.log(obj.proxyFun().ran === obj.proxyFun().ran);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment