Partial Application

suggest change

Similar to currying, partial application is used to reduce the number of arguments passed to a function. Unlike currying, the number need not go down by one.

Example:

This function:

function multiplyThenAdd(a, b, c) {
    return a * b + c;
}

… can be used to create another function that will always multiply by 2 and then add 10 to the passed value;

function reversedMultiplyThenAdd(c, b, a) {
    return a * b + c;
}

function factory(b, c) {
    return reversedMultiplyThenAdd.bind(null, c, b);
}

var multiplyTwoThenAddTen = factory(2, 10);
multiplyTwoThenAddTen(10); // 30

The “application” part of partial application simply means fixing parameters of a function.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents