Possible Duplicates:
What does this mean? (function (x,y)){…}){a,b); in JavaScript
What do parentheses surrounding a JavaScript object/function/class declaration mean?
Hi All
I don’t know what the following does:
(function(){
// Do something here
...
})(someWord) //Why is this here?;
My questions are:
- What’s the meaning of putting a function inside brackets .i.e.
(function(){});? - What do the set of brackets do at the end of a function?
I usually see these in jquery codes, and some other javascript libraries.
You’re immediately calling an anonymus function with a specific parameter.
An example:
This alerts “peter“.
In the case of jQuery you might pass
jQueryas a parameter and use$in your function. So you can still use jQuery in noConflict-mode but use the handy$: