Function.Prototype.delay = function(seconds){

// Remove the seconds from the parameters to pass the this function.

var args = [].slice.call(arguments, 1);

// call this function with the specified parameters in the specified amount of seconds.

var fnThis = this;

return setTimeout(function(){

fnThis.apply(undefined, args);

}, seconds * 1000);

}

 

ex) function showMsg(msg){ alert(msg); }

// In five seconds, show the appropriate message.

var timeoutID = showMsg.delay(5, "Five seconds have passed. ");

설정

트랙백

댓글