我将setInterval函数存储在一个数组中,并试图稍后将它传递给一个新变量。将setInterval和回调传递给一个新变量
this.clock = setInterval(() => {
this.duration = this.timer.formatTime(this.userTime)
if (this.duration === '00:00:00') {
clearInterval(this.clock);
this.timer.reset();
}
}, 1)
寻找在setInterval的对象this.clock.callback
有Closure._this对象,但我不知道如何访问它,因为它是与<function scope>
领域。
有没有办法将setInterval函数的当前内容传递给一个新变量?
如...
this.newClock = this.clock
和this.newClock
将具有相同的倒计时时间为this.clock
。
P.S.我新来张贴在stackoverflow。任何提出更好的问题提示或建议将不胜感激。
'setInterval'返回该间隔的间隔ID。你不能用它来获得访问功能。你可以做的是创建一个命名函数并告诉'setInterval'来调用它。 'function blah(){..}; setInterval(blah,1);' – IMTheNachoMan
@IMTheNachoMan发布那个答案。 – Barmar
@Barmar:谢谢。抱歉回合。 – IMTheNachoMan