Skip to content

Instantly share code, notes, and snippets.

@joelklabo
Created January 28, 2011 06:02
Show Gist options
  • Save joelklabo/799898 to your computer and use it in GitHub Desktop.
Save joelklabo/799898 to your computer and use it in GitHub Desktop.
Object.prototype.later = function (time, methodName) {
var args = Array.prototype.slice.apply(arguments, [2])
, func = this[ methodName ]
;
setTimeout(function() {
func.apply(self, args);
}, time);
}
var someObj = {
sayHi: function(n) {
var num = n || 5; // If no number is passed in default to 5
for (var i = 0; i < num; i += 1) {
console.log("Hiya!");
}
}
};
someObj.later(5000, 'sayHi', 7);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment