Function.prototype.bg = function(ms){ this.PID = setInterval(this,ms); return this; } Function.prototype.kill = function(){ clearInterval(this.PID) } /* var a = function(v){alert(v)}; var b = a.later(100); b("testtest"); b.cancel(); // cancel b.notify(); // do */ Function.prototype.later = function(ms){ var self = this; var func = function(){ var arg = func.arguments; var apply_to = this; var later_func = function(){ self.apply(apply_to,arg) }; var PID = setTimeout(later_func,ms); return { cancel : function(){clearTimeout(PID)}, notify : function(){clearTimeout(PID);later_func()} } }; return func; }; Function.prototype.wait = Function.prototype.later;