gpt4 book ai didi

javascript - 清除Famo.us框架中Timer类的setInterval

转载 作者:行者123 更新时间:2023-12-03 11:37:53 25 4
gpt4 key购买 nike

如何删除由famo.us计时器类设置的TimerInterval(我不完全理解famo.us如何包装natvie JS-setInterval方法)。在原生 JS 中我可以这样做:

var id = setInterval(fn, delay);
clearInterval(id);

我不想使用上述解决方案,因为 famo.us 不推荐它。我可以使用 famo.us 计时器类实现上述目标吗?

Timer.setInterval( function(){
console.log('exec function');
//this.doSomething() is a function defined on the classes prototype
this.doSomething();
}.bind(this), 3000);

//how can I referenc the above function?!
Timer.clear(/*function*/);

我需要将 setInterval 函数绑定(bind)到“this”,因为我在间隔执行中使用“this”上下文

非常感谢任何帮助。

最佳答案

添加对您正在使用的函数的引用,因为 setInterval 返回函数引用。

<强> Working Example code here in the Splash view: 及以下:

this.count = 0;
this.timerFunc = Timer.setInterval( function(){
this.count += 1;
this.surface.setContent('count ' + this.count);
}.bind(this), 1000);

this.surface.on('click', function(){
Timer.clear(this.timerFunc);
}.bind(this));

关于javascript - 清除Famo.us框架中Timer类的setInterval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26405298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com