【问题标题】:'currentApple' is already defined showing in jslint'currentApple' 已经定义在 jslint 中显示
【发布时间】:2013-09-26 02:33:18
【问题描述】:

我有一个 js 代码... 在那我运行了 js lint ...... 我有这个错误'currentApple'已经被定义.... 我需要从其他地方删除 var currentApple 吗? 在下面提供我的代码...

if(appleTab == Lifeline){
    var currentApple = appleWorklist.getcurrentAppleTime("currentAppointmentcurrentAppleTime");
    fo.allApples = currentApple;
}
else
{
    var currentApple = appleWorklist.getcurrentAppleTime("CalendarcurrentAppointmentcurrentAppleTime");
    fo.allApples = currentApple;
}

【问题讨论】:

    标签: javascript jquery html javascript-events jslint


    【解决方案1】:
    var currentApple;
    if (appleTab == Lifeline) {
        currentApple = /* etc. */
    

    【讨论】:

      【解决方案2】:

      javascript 中没有块作用域,所以你的代码 sn-p 中的currentApple 基本上是一样的。

      from Douglas Crockford的圣经,段落变量:

      JavaScript 没有块作用域,所以在块中定义变量 可能会使有其他 C 家族经验的程序员感到困惑 语言。在函数顶部定义所有变量。

      只需在函数开头使用 var 语句声明每个使用的变量一次。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-08-14
        • 1970-01-01
        • 1970-01-01
        • 2013-07-16
        • 2011-11-06
        • 2014-11-02
        • 1970-01-01
        • 2015-11-21
        相关资源
        最近更新 更多