Alw1n
asked on
jQuery syntax question
Hi, I have the code below which fires when a page has loaded:
(function() {
(function($) {
[Some code]
})(jQuery);
}).call(this);
I sort-of get the bit about anonymous functions but I don't understand why the '(jQuery)' is appended at the end of line 4?
(function() {
(function($) {
[Some code]
})(jQuery);
}).call(this);
I sort-of get the bit about anonymous functions but I don't understand why the '(jQuery)' is appended at the end of line 4?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sometime $ is used by an other framework or an other jQuery version.
Passing the jQuery object to the anonymous function allow you to use $ for all your jQuery code inside the anonymous function
[Some code] can safely use $ for a specifc jQuery object an not an other framework or an other jQuery version
Passing the jQuery object to the anonymous function allow you to use $ for all your jQuery code inside the anonymous function
[Some code] can safely use $ for a specifc jQuery object an not an other framework or an other jQuery version
jQuery(function ($) {
});
It will run on document.ready, within a namespace, and with jQuery defined as $, avoiding cross script conflicts
ASKER
I get that it is to ensure the '$' is tied to jQuery but as per your last post, is:
(function($) {
[Some code]
})(jQuery);
the same as
jQuery(function($) {
[Some code]
});
(function($) {
[Some code]
})(jQuery);
the same as
jQuery(function($) {
[Some code]
});
I put that after the jagadishdulal comment
Alternative shorthand for on document ready for avoiding cross script conflicts
Alternative shorthand for on document ready for avoiding cross script conflicts
jQuery(function ($) {
});
No more comments when the points have been assigned.
Open in new window