Javascript构造函数:如何查找计时器是否达到零?

Javascript构造函数:如何查找计时器是否达到零?,javascript,Javascript,我还没有完成这个脚本。所以我只是输入了它的外观 countdown.js将如下所示 function MyGame() { var declaration } MyGame.prototype.initialize() { //methods and variable initialize } //other logics “使用严格的” 函数倒计时(){ 这个秒=10; this.interval=null; } Countdown.prototype.startCountd

我还没有完成这个脚本。所以我只是输入了它的外观

countdown.js将如下所示

function MyGame() {
   var declaration
}
MyGame.prototype.initialize() {
   //methods and variable initialize
}
//other logics  
“使用严格的”
函数倒计时(){
这个秒=10;
this.interval=null;
}
Countdown.prototype.startCountdown=函数(){
var self=这个;
这个.renderTimer();
this.interval=setInterval(函数(){
如果(!self.isNegative()){
self.seconds=self.seconds-1;
self.renderTimer();
}
}, 1000);
}
Countdown.prototype.isNegative=函数(){

如果(this.seconds如此,请更改运行计时器的逻辑

MyGame.prototype.checkgameOver = function() {

    var interval;
    var self = this;
    interval = setInterval(function() {
        if(self.timer.getSeconds() <= 0 ) {
            self.gaemOver();
            clearInterval(interval);            
        }
    }, 1000);

 }

添加一个else语句…game.js和countdown.js-都是不同的文件。我需要将game.js对象传递给countdown.js吗?我已经实现了你所说的脚本。但是我计划不向countdown.js提供任何关于游戏的信息。但是现在我必须调用endgame函数。因此,使用一个触发计时器已达到零a的事件然后在脚本的另一部分中收听该事件。
MyGame.prototype.checkgameOver = function() {

    var interval;
    var self = this;
    interval = setInterval(function() {
        if(self.timer.getSeconds() <= 0 ) {
            self.gaemOver();
            clearInterval(interval);            
        }
    }, 1000);

 }
this.interval = setInterval(function() {
    if(self.isNegative()) { 
        //call game over code
    } else 
        self.seconds = self.seconds - 1;
        self.renderTimer();
    }
}, 1000);