Skip to content

Instantly share code, notes, and snippets.

@briangordon
Created January 27, 2014 20:04
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 briangordon/8656177 to your computer and use it in GitHub Desktop.
Save briangordon/8656177 to your computer and use it in GitHub Desktop.
Encapsulation in JavaScript
function MyClass () {
var privateVariable = 5;
var privateMethod = function () {
return privateVariable;
};
this.publicMethod = function () {
return privateMethod();
}
}
var myInstance = new MyClass();
console.log(myInstance.publicMethod());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment