繁体   English   中英

将setInterval和回调传递给新变量

[英]Passing setInterval and callback to a new variable

我将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相同。

PS我是新来的stackoverflow发布。 任何提出更好问题的技巧或建议,将不胜感激。

setInterval返回该间隔的间隔ID。 您不能使用它获取访问功能。 您可以做的是创建一个命名函数,并告诉setInterval调用它。 然后,您也可以在setInterval之外调用该函数。

function blah()
{
}

setInterval(blah, 1);

blah();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM