Skip to content

Instantly share code, notes, and snippets.

@andypearson
Created June 17, 2013 12:44
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 andypearson/5796590 to your computer and use it in GitHub Desktop.
Save andypearson/5796590 to your computer and use it in GitHub Desktop.
var myInstance = (function() {
var privateVar = '';
function privateMethod () {
alert(myInstance.public_var);
}
return { // public interface
public_var : 'Here',
publicMethod1: function () {
// all private members are accessible here
// access public methods and variables using the singleton name
myInstance.public_var = 'There';
myInstance.publicMethod2();
},
publicMethod2: function () {
privateMethod();
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment