Timeout for setTimeout
10 May 07 0 comments
Prototype provides a many alias functions like $() for document.getElementsById(), in the latest trunk you get an nice new way to execute functions delayed.
The old way was to use window.setTimeout(), now you can use yourFunction.delay().
Lets try something very simple. We want to simply tell the user after five seconds that he is five seconds on the site. Ok, this is actually a stupid example.
First we define a function that executes alert(). You think thats stupid to, but you’ll see why i define a new function later.
function tellFiveSeonds() {
alert('Your now five seconds on this page! Go away!');
}
Then we execute this function with a delay of five seconds with the following code:
tellFiveSeconds.delay(5);
But lets say we want to personalize this function and want to alert something like “Hey Bast! You are now five seconds on my page, please leave!”, then we will have to give the function an argument.
function tellFiveSeonds(username) {
alert('Hey ' + username + '! You are now five seconds on my page, please leave!');
}
But how do we still execute it with a delay of five seconds?
Like that:
tellFiveSeconds.delay(5, 'Bast');
delay takes the first argument for its own and passes the others to the function you want to execute, like you would do with any other function.

