What means and what will do this piece of code?
(function ($) {}(jQuery));
- What is relation between "$" and "jQuery".
- Do brackets "(", ")" on edges of code has any function? Do they do something?
What means and what will do this piece of code?
(function ($) {}(jQuery));
(function ($) {}(jQuery));
jQuery
is existing jQuery
object , $
is same jQuery
object within Immediately-Invoked Function Expression (IIFE) statement {}
Do brackets "(", ")" on edges of code has any function? Do they do something?
Yes. Comma ,
separates arguments to function
e.g.,
(function($, $$) {
// `$`:`{"abc":123}` ; `$$`:`{"def":456}`
console.log($["abc"], $$["def"]) // `123` , `456`
// set `$` within IIFE to object `{"abc":123}` ,
// set `$$` to object `{"def":456}`
}({"abc":123}, {"def":456}));
What is relation between "$" and "jQuery"?
$ is shorthand for jQuery. Sometimes $ is disabled as it may conflict with other Javascript libraries you are using. It is otherwise identical.
and refer this