1

我见过很多插件,其中包括诸如文档、窗口、未定义之类的对象到打开和关闭的参数中。

这是必要的吗?这是什么意思?什么时候应该使用这些?

;(function( $ , document, window, undefined) {
        "use strict";        

      $.fn.pluginname= function(options) {      

        //Code

      };
    })( jQuery, document, window, undefined);
4

1 回答 1

4

来自jqueryboilerplate.com

 // undefined is used here as the undefined global variable in ECMAScript 3 is
 // mutable (ie. it can be changed by someone else). undefined isn't really being
 // passed in so we can ensure the value of it is truly undefined. In ES5, undefined
 // can no longer be modified.

 // window and document are passed through as local variable rather than global
 // as this (slightly) quickens the resolution process and can be more efficiently
 // minified (especially when both are regularly referenced in your plugin).

为了获得一些额外的荣誉,请点击链接,您将看到为什么方法签名以分号开头。

此外,您的示例有点不正确:调用函数时,不应在最后一行传入“未定义”。我在上面粘贴的第一段解释了原因。

于 2013-02-08T15:24:11.137 回答