Skip to content

Instantly share code, notes, and snippets.

@arbel03
Created August 16, 2018 07:48
Show Gist options
  • Save arbel03/adb300c9cfac9a76467f1551d0506f48 to your computer and use it in GitHub Desktop.
Save arbel03/adb300c9cfac9a76467f1551d0506f48 to your computer and use it in GitHub Desktop.
Returns a new function that runs the original one with the provided arguments. The resulted callback doesn't require any arguments.
// Run `callback` on any function and provide arguments.
// Returns - a callback that takes no arguments and run the original
// function using the arguments provided in the call to `.callback()`
Function.prototype.callback = function() {
var args = arguments;
var thisFunc = this;
return function() {
return thisFunc.apply(thisFunc, Array.prototype.slice.call(args));
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment