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

Javascript 清除Famo.us框架中Timer类的setInterval,javascript,famo.us,Javascript,Famo.us,如何删除famo.us Timer类设置的TimerInterval(我不完全理解famo.us是如何包装natvie JS setInterval方法的)。在native JS中,我可以做到: var id = setInterval(fn, delay); clearInterval(id); 我不想使用上述解决方案,因为famo.us不推荐它。我如何通过famo.us Timer类实现上述目标 Timer.setInterval( function(){ console.log(

如何删除famo.us Timer类设置的TimerInterval(我不完全理解famo.us是如何包装natvie JS setInterval方法的)。在native JS中,我可以做到:

var id = setInterval(fn, delay);
clearInterval(id);
我不想使用上述解决方案,因为famo.us不推荐它。我如何通过famo.us Timer类实现上述目标

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函数绑定到“this”,因为我在间隔执行中使用了“this”上下文


非常感谢您的帮助。

类似的方法可能会奏效:

var fn = function(){
    console.log('exec function');
}
Timer.setInterval(fn, 3000);
// Time passes
Timer.clear(fn);

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

及以下内容:

this.count=0;
this.timerFunc=Timer.setInterval(函数(){
这是1.count+=1;
this.surface.setContent('count'+this.count);
}.绑定(本),1000);
this.surface.on('click',function(){
Timer.clear(this.timerFunc);
}.约束(这个);

谢谢你。没错。但问题是,我已经将setInterval绑定到“this”,因为我需要interval调用中的这个上下文。如果我不将它绑定到“this”,那么这就是EventHandler,这对我没有任何用处……bali182是正确的,尽管您需要您的用例,所以我在回答中包含了它。在他的示例中,您可以使用
this.fn
这就是我需要的解决方案。谢谢你帮我解决bali182和talves!