Skip to content

Instantly share code, notes, and snippets.

@heronmedeiros
Created May 6, 2015 19:05
Show Gist options
  • Save heronmedeiros/6fb2dc2824ba64a2776f to your computer and use it in GitHub Desktop.
Save heronmedeiros/6fb2dc2824ba64a2776f to your computer and use it in GitHub Desktop.
How to encapsulate js code
(function() {
var x = '';
function myFunction() {
console.log('Hello: ' + x);
}
x = 'Bob';
myFunction();
log(typeof x); // string
log(typeof myFunction); // function
})();
log(typeof x); // undefined
log(typeof myFunction); // undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment