Skip to content

Instantly share code, notes, and snippets.

@Rendez
Created December 18, 2009 11:14
Show Gist options
  • Save Rendez/259445 to your computer and use it in GitHub Desktop.
Save Rendez/259445 to your computer and use it in GitHub Desktop.
Function.implement('repeat', function(number, fn, bind){
return function(){
for (var i = 1; i <= number; i++) fn.call(this, i, number);
};
});
mySillyFunction = function(){
console.log('Moo said the dog; Meow said the bird');
};
mySillyFunction.repeat(3, mySillyFunction);
Function.implement('times', function(times, bind){
var self = this, i = arguments[2] || 0, bind = bind || null;
return function(){
(!bind) ? self(i++, times) : self.call(this, i++, times);
if (i < times) return Function.times.apply(self, [times, bind, i]);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment