delay method

In Javascript, setTimeout() is used to delay a function or an expression after a specified number of milliseconds. To delay a function, it's usually expressed as,

var t = setTimeout(foo, 1000);
function foo() {

The function foo() is fired after 1 seconds.

Here we could extend the prototype property of the native object Function and get an extended method - delay().

Function.prototype.delay = function(del) {
    var _this = this;
    (function() { 

Now we can express the above code as,


That's it. A simple method that could ne used in Javascript animation.

Social Bookmark if it is useful.