setTimeout - 将变量作为时间传递 [英] setTimeout - Pass variable as time
本文介绍了setTimeout - 将变量作为时间传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 setTimeout,我希望能够使用一个变量作为计时器:
I have a setTimeout, and I want to be able to use a variable as the timer:
var that = this;
var time = this.spawnTime;
setTimeout( function(time){
that.SpawnCounter();
}, time);
这似乎不起作用.任何想法为什么?
This doesn't seem to do the trick. Any ideas why?
谢谢
推荐答案
var that = this;
var time = 1000;
setTimeout( function(time){
that.SpawnCounter();
}, time);
上面的代码应该可以工作.也许问题在于 this.spawnTime
不是数字或无效.
The code above should work.
Maybe the problem is that this.spawnTime
is not numeric or invaild.
这篇关于setTimeout - 将变量作为时间传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文