Last active
August 29, 2015 13:56
-
-
Save crongro/8934987 to your computer and use it in GitHub Desktop.
singleton pattern by codepen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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