在定义之前使用的Jslint settimeout

时间:2014-03-09 02:29:05

标签: javascript settimeout jslint

var AnimationManager = function (time, completionMethod) {
    "use strict";
    this.animationObjects = [];
    this.time = time;
    this.add = function (animationObject) {
        this.animationObjects.push(animationObject);
    };
    this.completionMethod = completionMethod;
    this.currentStage = 0;
    this.maximumStage = this.time * FPS;

    this.tick = function () {
        this.currentStage += 1;
        if (this.currentStage < this.maximumStage) {
            setTimeout(this.tick.bind(this), 1000.0 / FPS);
        } else {
            //Set manager to nil in the completion method
            this.completionMethod();
        }

        var i;
        for (i = 0; i < this.animationObjects.length; i += 1) {
            this.animationObjects[i].applyAnimation(this.currentStage);

        }
    };

    //Call this to start
    this.startAnimation = function () {
        this.timer = setTimeout(this.tick.bind(this), 1000.0 / FPS);
    };
};
括号中的JSLint给了我一些恼人的错误;两个像:'setTimeout' was used before it was defined. setTimeout(this.tick.bind(this), 1000.0 / FPS);它在谈论世界的什么!

它也可以通过console.log控制台来定义。

1 个答案:

答案 0 :(得分:4)

您必须告诉JSLint您的代码在浏览器中运行,并且还需要假定console已定义。

将它置于代码之上:

/*jslint browser: true, devel: true */

老实说,我更喜欢JSHint,而不是意见。