Search code examples
javascriptjqueryiifeself-invoking-function

Javascript: how to name a IIFE


Im working on a image slider plugin made in javascript! yes... I was bored
and I want it to kick off immediately so I tried to make a immediately invoking function expression (IIFE) like in the jQuery source code:

(function blahBlahBlah(someJquery, thing, lalala, jquery){
 //You could have no parameters if you'd wanted but for the sake of this question I just added some gibberish...
})(jQuery);

I tried to make a immediately invoking function expression (IIFE) like that and failed ::) this is what I've tried:

(function blahBlahBlah(someNames, someThing, lalala, Me){

})(MyName);

and failed but it works when I replace the last parameter with window?
I've even tried a left sided variable like this:

(function blahBlahBlah(someNames, someThing, lalala, Me){
 MyName = window;
})(MyName);

why does it do that and how can I get effect I'm looking for? Thanks in advance,- Millzie.


Solution

  • What you were trying to do works fine:

    (function sayName(name) { console.log(name) } )('Millzie')