Forum Moderators: open
var $elem = jQuery(this); ;(function($) {
...
})(jQuery); ;(function($) {
...
function startHandler(event) {
var $elem = jQuery(this);
...
}
})(jQuery); Is one faster than the other?
Or maybe just that he wrote the first part in 2010 (for example) and added the second in 2016 without updating the first?
jQuery(this) is identical to $(this) in most cases. $ is just an alias for jQuery. However, jQuery allows you to relinquish control of the $ variable, in case you're loading another library that also uses a global $ variable. See [api.jquery.com...] var log = console.log (function ($) {})(jQuery); var log = console.log(function($) {})(jQuery); var log = console.log;(function($) {})(jQuery); Is this the same as $(function() { ... })?
$ within the function: function ($) {} jQuery. This means the value of $ within the function is going to be the jQuery object passed in. (function ($) {
// $ === jQuery
})(jQuery);