Skip to content

Instantly share code, notes, and snippets.

@arjaneising
Created February 24, 2012 13:48
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 arjaneising/1901042 to your computer and use it in GitHub Desktop.
Save arjaneising/1901042 to your computer and use it in GitHub Desktop.
JS Scoping trick
var forUserFunctions = (function(window, document) {
var privateElm = document.getElementById('supersekrit');
function setNewText(newText) {
privateElm.innerHTML = newText;
}
function capitalize() {
privateElm.innerHTML = privateElm.innerHTML.toUpperCase();
}
return {
setNewText: setNewText,
capitalize: capitalize
};
})(window, document);
forUserFunctions.setNewText('Foo bar lol');
forUserFunctions.capitalize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment