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

时间:2014-11-26 01:50:38

标签: javascript jquery google-closure-compiler

我正在尝试针对包含此扩展程序的代码运行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

1 个答案:

答案 0 :(得分:0)

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