Created
January 27, 2014 20:04
-
-
Save briangordon/8656177 to your computer and use it in GitHub Desktop.
Encapsulation in JavaScript
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
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