Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
curryAndCall as a prototype method for Functions
Function.prototype.curryAndCall = function () {
var args =;
var curry = function (originalFunc, collectedArgs) {
return function () {
var args =;
if (args.length + collectedArgs.length >= originalFunc.length) {
return originalFunc.apply(originalFunc, collectedArgs.concat(args));
} else {
return curry(originalFunc, collectedArgs.concat(args));
if (args.length >= this.length) {
return this.apply(this, args);
} else {
return curry(this, args);
// Test subject: function with 4 arguments.
var logFour = function (a, b, c, d) {
console.log('--------->', a, b, c, d);
// Keep pre-populating arguments for logFour() until we have all four,
// then call the original function with all collected arguments.
Copy link

timotgl commented Mar 7, 2016

Inspired by but I tried to avoid using additional helper functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment