-
-
Save karbassi/401841 to your computer and use it in GitHub Desktop.
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
// what does this do?: | |
(function(){ | |
var i = 5; | |
}()); | |
// What this does is create an anonymous function then assigns a local variable 'i' | |
// with an integer value of 5 to it. Then it runs the function. | |
(function(){}); // creation of anonymous function | |
(function(){}()); // creation of anonymous function which is then ran. | |
// is it like a javascript hack equivalent to the jQuery(document).ready()? e.g.: | |
$(function() { | |
var i = 5; | |
}); | |
// $(); is short-code for jQuery(document).ready(); Some use this for it's shortness, | |
// but it doesn't give you a no-conflict use of the $ character. This may problems | |
// if your project uses prototype or any other javascript library that uses $. | |
// Good reference: http://api.jquery.com/ready/ |
PS
then assigns a local variable 'i' with an integer value of 5 to it.
Wow, you are either very verbose, or think I'm a complete javascript n00b. Knowing you, I'm entirely sure it is the verbosity. ^_^
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, thanks Karbassi! You kind of failed to answer my question, but that is entirely my fault - I failed to ask you the right question. But you gave me the stuff I needed to hit up Google successfully this time. Here is what I meant to ask, and some good answers:
http://stackoverflow.com/questions/1643321/javascript-why-the-anonymous-function-wrapper