質問

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 in brackets is giving me some annoying errors; two like: 'setTimeout' was used before it was defined. setTimeout(this.tick.bind(this), 1000.0 / FPS); What in the world is it talking about!

It also does this with console.log console is undefined.

役に立ちましたか?

解決

You must tell JSLint that your code runs in a browser and that it also needs to assume console is defined.

Put this on top of your code:

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

Honestly I prefer JSHint which is less opiniated.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top