-1

Possible Duplicate:
What do parentheses surrounding a JavaScript object/function/class declaration mean?
What does (function($) {})(jQuery); mean?

I am trying to understand how Edge works so I can use my own code,

I have not come accross this before, but what does this mean:

 (function(symbolName) {


      //CODE


   })("stage");
Community
  • 1
  • 1
nmyster
  • 454
  • 1
  • 7
  • 20

3 Answers3

5

It's an anonymous function that is defined and then called with the argument "stage"

OnResolve
  • 4,016
  • 3
  • 28
  • 50
2

It is the similar to doing:

var myfunc = (function (symbolName) {
        //CODE
    });

myfunc("stage");

OR

function myfunc(symbolName) {
    //CODE
}

myfunc("stage");

except that when the function is defined in either of these ways it will be 'hoisted' to the top of the block scope - but thats a whole other topic.

David
  • 8,340
  • 7
  • 49
  • 71
1

In Javascript you can ddefine anonymous functions by simply typing:

(function(){alert("Hello")});  /* ok, this do nothing, but it is correct */

It is also possible to call a function directly:

(function(){alert("Hello")})(); /* alert is displayed */

If the function has arguments, you have to specify the arguments:

(function(args){alert(args)})("Hello"); /* alert is displayed with the passed arguments */

I suggest you this tutorial.

Alberto De Caro
  • 5,147
  • 9
  • 47
  • 73
  • 1
    The first one isn't technically valid. The interpreter will see it as a function declaration that is missing its name. You need to coerce it into an expression in order to make it anonymous. If you wrapped it in parens, it would be valid `(function(){})` – I Hate Lazy Oct 02 '12 at 12:18