Skip to content

Instantly share code, notes, and snippets.

@flyingzl
Created January 23, 2013 13:06
Show Gist options
  • Select an option

  • Save flyingzl/4605351 to your computer and use it in GitHub Desktop.

Select an option

Save flyingzl/4605351 to your computer and use it in GitHub Desktop.
javascript singleton pattern
var Singleton =(function(){
var _instance ;
function init(){
return {
method: function(){
return 1;
},
property: 'hello'
}
}
return {
getInstance: function(){
!_instance && ( _instance = init() );
return _instance;
}
}
})();
Singleton.getInstance().method();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment