Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTimeout - Pass variable as time

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?

Thanks

like image 568
Oliver Jones Avatar asked May 17 '26 04:05

Oliver Jones


1 Answers

var that = this;
var time = 1000;

setTimeout( function(time){ 
    that.SpawnCounter();
}, time);

The code above should work. Maybe the problem is that this.spawnTime is not numeric or invaild.

like image 60
HasanAboShally Avatar answered May 21 '26 16:05

HasanAboShally