繁体   English   中英

JSLint意外的“ that”消息

[英]JSLint unexpected 'that' message

我刚刚开始使用JSLint来确保我正在创建的JavaScript代码至少符合某些标准,并且得到了一个令人困惑的消息:

JSLint: Unexpected 'that'.

该代码是实现进度条的解决方案的一部分,该过程的一部分是处理计时器和回调的该对象,如下所示(这是从较大文件开头的摘录,如果需要,我可以添加整个文件) :

var ProgressHandler = function () {
    "use strict";

    // Build a new object
    var that = {};

    // Add basic properties
    that.taskid = 0;
    that.timerid = 0; // Timer ID used to push refreshes
    that.progressUrl = ""; // URL to invoke to read progress
    that.interval = 500; // The interval for progress refresh
    that.taskProgressCallback = null; // The user-defined callback that refreshes the UI 
    that.taskCompletedCallback = null; // The user-defined callback that finalizes the call 

    // Set progress url
    that.setProgressUrl = function (url) {
        that.progressUrl = url;
        return this;
    }

    // Set frequency of refresh
    that.setInterval = function (interval) {
        that.interval = interval;
        return this;
    };

该消息出现在that.setInterval开头的行上。 我还有其他用途,但是JSLint还说它此时停止处理。 我尝试搜索此消息,但此处或在jslinterrors.com上未特别列出。

为什么会出现这种情况,我该如何解决? 还是应该忽略它?

问题似乎是您没有; that.setProgressUrl的定义that.setProgressUrl 更改为:

    // Set progress url
    that.setProgressUrl = function (url) {
        that.progressUrl = url;
        return this;
    };

解决了所报告的问题。 然后,您会遇到一个问题,即文件末尾缺少左花括号和半冒号,不确定是否只是复制和粘贴问题。 完整的脚本应如下所示:

var ProgressHandler = function () {
    "use strict";

    // Build a new object
    var that = {};

    // Add basic properties
    that.taskid = 0;
    that.timerid = 0; // Timer ID used to push refreshes
    that.progressUrl = ""; // URL to invoke to read progress
    that.interval = 500; // The interval for progress refresh
    that.taskProgressCallback = null; // The user-defined callback that refreshes the UI 
    that.taskCompletedCallback = null; // The user-defined callback that finalizes the call 

    // Set progress url
    that.setProgressUrl = function (url) {
        that.progressUrl = url;
        return this;
    };

    // Set frequency of refresh
    that.setInterval = function (interval) {
        that.interval = interval;
        return this;
    };
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM