Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 732
Millzie Avatar asked Jan 19 '26 13:01

Millzie


1 Answers

What you were trying to do works fine:

(function sayName(name) { console.log(name) } )('Millzie')
like image 91
dezman Avatar answered Jan 21 '26 04:01

dezman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!