Currying and Bind

Currying is a technique to bind a function to a subset of arguments (Effective JavaScript by David Herman, p.75). In the example, we can see that two arguments (protocol and domain) are passed as the arguments of the function simpleURL, when it is used in the higher-order function, that is - map method. The third argument "path" comes from each array element of the iteration of the map method.

var paths = ["fruit", "veggie", "bread"];

function simpleURL(protocol, domain, path) {
    return protocol + "://" + domain + "/" + path;
}

var urls = paths.map(function(path) {
    return simpleURL("http", "example.com", path)
});

console.log(urls)
//["http://example.com/fruit", "http://example.com/veggie", "http://example.com/bread"]

This can be concisely written using currying and bind like this.

var urls = paths.map(simpleURL.bind(null, "http", "example.com"));