What happens if I do not pass the jQuery object invoking the anonymous function:
$(function($) {...}
instead of
$(function($) {...} (jQuery);
It still seems to work in all scripts so why pass it explicitly as stated everywhere on the net?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What if you have another library that uses $ as its main object? In that case, it is possible that the second library’s object be passed to your function and your plugin break.
Imagine that you use a library of mine called foo. In that library I use
#as my global object. To use my library, you start your code with#as:Now imagine that you use still another library which like jQuery uses
$sign as its root object. (I think Google Analytics is such a library). In that case, the latest library to load in the browser, wins the race and takes the$sign under control. In this case, when you want to use$in your plugin, you’re actually referring to a wrong library. But when explicitly passing jQuery name (jQuery’s root object is both accessible using$sign or jQuery), then you can get sure that in the scope of your plugin, you use jQuery, not another library. 🙂