使用 fn.extend() 和 Google 闭包编译器扩展 jQuery

Extend jQuery with fn.extend() and Google closure compiler?

本文关键字:闭包 编译器 扩展 jQuery Google fn extend 使用      更新时间:2023-09-26

我正在尝试针对包含此扩展的代码运行Google闭包编译器:

jQuery.fn.extend({
    /** 'brief Apply the makeButton() function to a jQuery() object.
     *
     * This function calls our snapwebsites.Output.makeButton() function
     * on all the objects in this jQuery and returns the necessary reference
     * to continue the jQuery chain.
     *
     * We use this function when we setup a click() handler on a button,
     * for example:
     *
     * 'code
     *    jQuery(".add-user-button")
     *      .makeButton()
     *      .focus()
     *      .click(function(e)
     *          {
     *              ...snip...
     *          });
     * 'endcode
     *
     * This gives users the possibility to use Enter, Space, or Click
     * with the Mouse on that button.
     */
    makeButton: function()
    {
        return this.each(function(){
                snapwebsites.Output.makeButton(this);
            });
    }
});

我得到命令行和警告:

# The command line is one single line, broken up here for display
java -jar ../tmp/google-js-compiler/compiler.jar --js_output_file
     .../snapwebsites/BUILD/snapwebsites/analysis/js-compile/server-access.min.js
     --warning_level VERBOSE --compilation_level ADVANCED_OPTIMIZATIONS
     --externs .../snapwebsites/tmp/google-js-compiler/closure-compiler/contrib/
               externs/jquery-1.9.js
     --externs plugins/output/externs/jquery-extensions.js
     --js plugins/output/output.js --js plugins/server_access/server-access.js
plugins/output/output.js:925: WARNING - dangerous use of the global this object
       return this.each(function(){
              ^

有没有办法避免这个警告? this显然不是全球this.

jQuery代码一般与ADVANCED_OPTIMIZATIONS不兼容。请参阅 https://stackoverflow.com/a/16463099/1211524