Skip to content

Instantly share code, notes, and snippets.

@sarbull
Created July 30, 2016 14:27
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 sarbull/fad3a4d3feea9f0286d85c9feef65661 to your computer and use it in GitHub Desktop.
Save sarbull/fad3a4d3feea9f0286d85c9feef65661 to your computer and use it in GitHub Desktop.
var singleton = (function () {
var instance;
function init() {
function privateMethod(){
console.log( "I am private" );
}
var privateVariable = "I am a private variable";
var privateRandomNumber = Math.random();
return {
publicMethod: function () {
console.log( "I am a public method" );
},
publicProperty: "I am a public property",
getRandomNumber: function() {
return privateRandomNumber;
}
};
};
return {
getInstance: function () {
if ( !instance ) {
instance = init();
}
return instance;
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment