JavaScript Javascript Syntax: Immediately Invoked Function Expression (IIFE) with parameters

I have always seen code like this:

(function(){
   //code here
})();

How does this code work? Which function receives which parameters?

(function(factory){
   //code here
}(function($){
  //other code here
}));
Answer:1
function($){
  //other code here
}

This block is passed as a parameter to the outer IIFE. It might be clearer to write it like this:

var factoryDef = function($) { ... };

(function(factory) {
    // this is the outer IIFE
    var someVar = {};
    // you can call:
    factory(someVar);
    // the previous line calls factoryDef with param someVar
}(factoryDef));

So factory(someVar) is the same as factoryDef({}); the latter is simply the value of factory (which is the function factoryDef) called with the value of someVar (which is {}.)

Does that make sense?

Answer:2

I guess the better question here is more general: how do I debug errors for deployed apps? Does Meteor have commands/logs I can look at? I'm really not sure where to begin because everything works ...

I guess the better question here is more general: how do I debug errors for deployed apps? Does Meteor have commands/logs I can look at? I'm really not sure where to begin because everything works ...

  1. exception in defer callback
  2. deferred exception callback

i am working on codeigniter. I want to display data from backend to the view files. here is my code $result = $obj->get_details(); if ($result[0]) { for ($i=0; $i<count($result)...

i am working on codeigniter. I want to display data from backend to the view files. here is my code $result = $obj->get_details(); if ($result[0]) { for ($i=0; $i<count($result)...

I have (interactive - like python shell) C++ console application and went playing with Emscripten (to transcompile from C++ to JS). All is well, but I'd like the JS's focus-stealing prompt to be ...

I have (interactive - like python shell) C++ console application and went playing with Emscripten (to transcompile from C++ to JS). All is well, but I'd like the JS's focus-stealing prompt to be ...

I'm breaking my head for few days trying to solve this and can't seems to find answer. I'm trying to build a proof of concept for video player using HTML5 that works on Android and IOS, the trick is ...

I'm breaking my head for few days trying to solve this and can't seems to find answer. I'm trying to build a proof of concept for video player using HTML5 that works on Android and IOS, the trick is ...

  1. best way display snakeskin
  2. desmume best display method