0

Hello I've got a function like this one.

function doSomething () {

     ( function () {
        // callbacks and code
       }
     )();
}

I am not use to that typing, I'm looking forward to understand how is interpreted by the browser or what does it mean the ( function () ) (); Thought I know the differences between calls and assigns , I can't read this properly , surely is something simple but I don't really get it. Thanks.

Rob
  • 14,746
  • 28
  • 47
  • 65
Moises
  • 23
  • 5
  • IIFE = Immediately Invoked Function Expression http://adripofjavascript.com/blog/drips/an-introduction-to-iffes-immediately-invoked-function-expressions.html – azium Sep 25 '15 at 03:07
  • In javascript a function can be attached to a name. The outer one is that. Similar a name for function followed by () without any space means the command to execute it. The inner function is not attached to any name. But the () are attached immediately after which commands to run it there. You can call it from elsewhere and hence its anonymous function. – kandelvijaya Sep 25 '15 at 03:28

1 Answers1

3

Is a self invoked anonymous function:

A self-invoking anonymous runs automatically/immediately when you create it and has no name, hence called anonymous. Here is the format of self-executing anonymous function:

(function(){
 // some code…
})();

https://sarfraznawaz.wordpress.com/2012/01/26/javascript-self-invoking-functions/

kamus
  • 797
  • 1
  • 6
  • 15