Last active
January 13, 2016 10:34
-
-
Save h3xxx/978ddbf911d804bf1707 to your computer and use it in GitHub Desktop.
Private and public functions in JS.
This file contains hidden or 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
// taken from http://stackoverflow.com/questions/55611/javascript-private-methods | |
function Restaurant() { | |
var myPrivateVar; | |
var private_stuff = function() { // Only visible inside Restaurant() | |
myPrivateVar = "I can set this here!"; | |
} | |
this.use_restroom = function() { // use_restroom is visible to all | |
private_stuff(); | |
} | |
this.buy_food = function() { // buy_food is visible to all | |
private_stuff(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment