【问题标题】:Shadowing of global property 'undefined'全局属性“未定义”的阴影
【发布时间】:2019-07-12 01:15:15
【问题描述】:

谁能给我一些关于修复我在使用 JSLint 时遇到的警告的指示。

我有以下代码:

/* global window, define, module */
(function(global, factory) {
    var Gauge = factory(global);
    if(typeof define === "function" && define.amd) {
      // AMD support
      define(function() {return Gauge;});
    }else if(typeof module === "object" && module.exports) {
      // CommonJS support
      module.exports = Gauge;
    }else {
      // We are probably running in the browser
      global.Gauge = Gauge;
    }
})(typeof window === "undefined" ? this : window, function(global, undefined) {

在最后一行 (typeof window === "undefined" ... 我收到此警告:

Line 14: Shadowing of global property 'undefined' no-shadow-restricted-names

如果可能的话,我想去掉这个警告。

【问题讨论】:

  • 我猜问题是您使用别名工厂将 undefined 传递给您的函数,因此您可能会修改它,所以这就是 no-shadow-restricted-names 给您警告的原因,您可以尝试使用 function(global, factory = undefined) ...
  • 谢谢@SilvioBiasiol 修复了警告。
  • 没问题,乐于助人:)

标签: javascript jslint


【解决方案1】:

您要么希望从the function(global, undefined) { function 中删除undefined 参数,要么禁用该特定行上的警告(因为它可以防止其他 脚本未能注意此警告)。或者,使用构建系统自动将此 UMD 标头添加到您的模块中,并仅在源代码上运行 jslint。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    相关资源
    最近更新 更多