开发者

Jquery ready function conventions

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜