【问题标题】:Extend jQuery with fn.extend() and Google closure compiler?使用 fn.extend() 和 Google 闭包编译器扩展 jQuery?
【发布时间】:2014-11-26 01:50:38
【问题描述】:

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

【问题讨论】:

标签: javascript jquery google-closure-compiler


【解决方案1】:

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

【讨论】:

  • 啊...它似乎可以与闭包编译器默认提供的 jQuery extern 一起使用。但我想那是因为这些只是简单的定义。虽然您提供某种形式的兼容版本很酷。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多