如何清除JS中对象的超时?

时间:2019-02-13 20:03:10

标签: javascript object undefined cleartimeout

我的超时有问题,我在一个对象中声明了它们,但无法清除它,它只是告诉我在尝试将其记录在控制台中时未定义。有一种特殊的方法吗?

我试图这样声明它: this.disapear = window.setTimeout(this.endgame,this.timer); 但这无济于事。

constructor() {
    this.elem.addEventListener('click', this.remove); 
    this.disappear = setTimeout(this.endgame, this.timer); 
}

remove() {
    clearTimeout(this.disappear); 
}

这里是个主意:我单击该元素(它显示在导航器中),该元素随着超时而消失。该元素实际上消失了,但是超时仍然存在。

感谢您的时间!

0 个答案:

没有答案