开发者

Jquery ready function conventions

开发者 https://www.devze.com 2023-03-09 06:35 出处:网络
what is the difference b/w $(function(){ }); and (function ($) { //found this code in jquery uobtrusive ajax

what is the difference b/w

$(function(){

});

and

(function ($) {
//found this code in jquery uobtrusive ajax
}(JQuery));

first code snippet is simply shorthand for document ready. i have no idea about second code snippet: what does it do and how does it differ from the first co开发者_开发知识库de snippet.


The second snippet creates an anonymous function and executes it immediately, without waiting for anything to load.

It's used to create a local variable (parameter) named $ that refers to jQuery, even if someone calls jQuery.noConflict().

It also hides internal variables created in the function from the global scope.

0

精彩评论

暂无评论...
验证码 换一张
取 消