For the function (function($){})(), I've seen it with the word jQuery in it, why is that?

后端 未结 1 1421
被撕碎了的回忆
被撕碎了的回忆 2020-12-12 02:48

For the function (function($){})(), I\'ve seen it with the word jQuery in it, why is that?

I have read this page Javascript: why does jQuery do this: (function(){ ..

相关标签:
1条回答
  • 2020-12-12 03:24

    Is a simple function invocation, the jQuery object is sent as an argument to the anonymous function, e.g.:

    (function (foo) {
      alert(foo); // alerts "hello"
    })("hello");
    

    It's a common pattern to define plugins, basically permits you to reference the jQuery object as $ in the scope of the anonymous function, even if jQuery is running in noConflict mode.

    0 讨论(0)
提交回复
热议问题