Skip to content Skip to sidebar Skip to footer

Using Settimeout() For Large Values

I'm trying to get an event to fire after five minutes. I'm using the following code: setTimeout(tweet(name, type), 5 * 60 * 1000); It is firing after a while, but not nearly five

Solution 1:

You are calling tweet immediately and passing its return value to setTimeout.

You need to pass a function to setTimeout. You haven't included the code for tweet, but I'm going to assume that it doesn't return a function.

setTimeout(function () { tweet(name, type); }, 5 * 60 * 1000);

Solution 2:

Quentin's solution works, but you can also use this form:

setTimeout(tweet(name, type), 5 * 60 * 1000);

functiontweet(name, type) {
    returnfunction(name, type) {
    };
}

It has some use cases when you want to keep some values in a closure.

Post a Comment for "Using Settimeout() For Large Values"