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



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

i have seen code this:

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

how code work? function receives parameters?

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

function($){ //other code here }

this block passed parameter outer iife. might clearer write this:

var factorydef = function($) { ... }; (function(factory) { // outer iife var somevar = {}; // can call: factory(somevar); // previous line calls factorydef param somevar }(factorydef));

so factory(somevar) same factorydef({}); latter value of factory (which function factorydef) called value of somevar (which {}.)

does create sense?

javascript iife

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -