Beginner
Beginner

Reputation: 223

Meaning of jquery function (jquery, mytype)

What $, bi and undefined refers here. And what is the use of Jquery and myType.?

TIA

function($, bi, undefined) {

}) (Jquery, myType);

Upvotes: 0

Views: 49

Answers (2)

Radonirina Maminiaina
Radonirina Maminiaina

Reputation: 7004

It's a IIFE and you send the param jQuery and myType to that anonymous function.

(function($, bi, undefined) {

})(jQuery, myType);

For example:

var foo = function ($, bi, undefined) {

}

and you call

foo(jQuery, myType);

Upvotes: 1

T.J. Crowder
T.J. Crowder

Reputation: 1074385

$, bi, and undefined are all parameters to the anonymous function, which is then called with the arguments jQuery and myType. So $ will get the value of jQuery, bi will get the value of myType, and undefined will get the value undefined (because no argument was supplied for that parameter). Those identifiers will be in-scope within the function.

Why would someone write this?

  • Re $: To use $ instead of jQuery within the function, even if jQuery's noConflict mode was being used outside the function.

  • Re bi: To get the value of myType as bi (for whatever reason, it's not some standard thing).

  • Re undefined: Paranoia. Specifically, so that within the function the identifier undefined really would definitely have the value undefined. For historic reasons, undefined is a global variable, not an identifier, and it's possible to shadow it by declaring it within a scope and assigning it a value. Sometimes people used patterns like these to avoid worrying that undefined may have been shadowed in this way. (Once upon a time you could even redefine it at global scope, but you can't anymore.)

Upvotes: 1

Related Questions