Created
September 9, 2014 04:52
-
-
Save greggnakamura/fa3c88bbf1f311fb5cc2 to your computer and use it in GitHub Desktop.
Javascript: Self-invoking anonymous function example
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
// Immediately invoked function | |
// Code treated as local variables and functions | |
// Anonymous function, wrapped by a set of parenthesis, allows execution of anonymous function | |
(function () { | |
var foo = 'hello, window'; | |
var bar = function () { | |
var foo = 'hello, function'; | |
alert(window.foo); // returns undefined | |
}; | |
bar(); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment