Lodash partial vs Native Function bind

Both Lodash’s _.partial and JavaScript's native Function.prototype.bind are used for partial application, allowing you to pre-fill a function's arguments. However, they differ fundamentally in how they handle the execution context (this), how they order and fill arguments, and their flexibility with placeholders. While Function.prototype.bind is primarily designed to lock a function's this context while optionally pre-filling arguments, _.partial is designed purely for argument pre-filling without altering the execution context, while also supporting argument placeholders.

1. Handling of the this Context

The most critical distinction between the two methods is how they manage this.

function greet(greeting, punctuation) {
  return `${greeting}, ${this.name}${punctuation}`;
}

const user = { name: "Alice" };

// Native bind locks the context as its first argument
const boundGreet = greet.bind(user, "Hello");
console.log(boundGreet("!")); // "Hello, Alice!"

// Lodash partial does not bind 'this'
user.partialGreet = _.partial(greet, "Hello");
console.log(user.partialGreet("!")); // "Hello, Alice!"

2. Support for Placeholders

Native Function.prototype.bind applies arguments strictly from left to right. You cannot skip an argument to be supplied later.

Lodash provides a placeholder feature (_ or _.partial.placeholder), allowing you to pre-fill arguments in any position, not just sequentially from the left:

function buildUrl(protocol, domain, path) {
  return `${protocol}://${domain}/${path}`;
}

// Pre-fill the first and third arguments, leaving the middle for later
const getSecuredDoc = _.partial(buildUrl, "https", _, "index.html");

console.log(getSecuredDoc("example.com")); 
// Output: "https://example.com/index.html"

To achieve this with native JavaScript, you must wrap the call in a custom closure or arrow function.

3. Argument Placement Flexibility (_.partialRight)

While bind strictly appends incoming arguments to the end of the pre-filled arguments, Lodash also offers _.partialRight. This companion function allows arguments to be partially applied from the right side of the parameter list:

function divide(a, b) {
  return a / b;
}

const half = _.partialRight(divide, 2);
console.log(half(10)); // 5 (10 / 2)

Summary of Differences