Created
December 3, 2012 04:10
-
-
Save d48/4192640 to your computer and use it in GitHub Desktop.
to make javascript object method public
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
var hey = {}; | |
(function() { | |
function woot() { | |
return 'hi'; | |
} | |
function who() { | |
return 'me'; | |
} | |
hey.woot = woot; | |
})(); | |
// outputs: hi | |
console.log(hey.woot()); | |
// outputs: who is not defined | |
console.log(who()); | |
console.log(hey.who()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pattern for making a method public and leaving others as private