I often see this described as the way to assure a safe environment for a jQuery plugin:
(function($){
$.fn.myPlugin = function() {
...
};
})(jQuery);
Wouldn’t it be better to also safeguard undefined, like so:
(function($, undefined){
$.fn.myPlugin = function() {
...
};
})(jQuery);
Or does it not matter? and if so, why?
It is probably not necessary. If you test whether a variable is
undefined, you should prefer usinganyway.
“Safeguarding” jQuery on the other hand is something you definitely should do, otherwise your plugin will not work if jQuery is used in
noConflictmode.