Lodash _.bindKey() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Creates a function that invokes the method at object[key] with partials prepended to the arguments it receives. Part of Lodash 4.x Function (since 0.10.0).

Pass the required arguments shown below. Most helpers return a new function you call later.

Syntax

Call _.bindKey. Start with this line.

Lodash
_.bindKey(object, key, …partials)
CallWhat it does
_.bindKey(object, key, …partials)Primary signature.
_.bindKey(func)Wrap or transform a function.

Prefer import bindKey from "lodash/bindKey" when you want a smaller bundle.

Library declarations
Lodash
_.bindKey(object, key, …partials)

Parameters

ParameterDescription
objectRequired. Owner of the method; also used as this
keyRequired. Property name looked up on each call
partialsOptional. Leading arguments (or placeholders)

Return Value

Return ValueDescription
*New bound function

Lodash Examples

Example 1 — Official Basic Call

Bind a method by name and prepend a greeting.

Lodash
var object = {
  user: "fred",
  greet: function (greeting, punctuation) {
    return greeting + " " + this.user + punctuation;
  }
};

var bound = _.bindKey(object, "greet", "hi");
bound("!");
// → "hi fred!"
Try It Yourself

How It Works

  1. Key. Wrapper stores "greet", not the function body.
  2. Partial. "hi" is prepended as the greeting.
  3. Call. Looks up object.greet and runs it with this = object.
  4. Result. Same string as the official Lodash docs.

Example 2 — Redefine the Method

After swapping greet, the same wrapper uses the new implementation.

Lodash
var object = {
  user: "fred",
  greet: function (greeting, punctuation) {
    return greeting + " " + this.user + punctuation;
  }
};

var bound = _.bindKey(object, "greet", "hi");
bound("!"); // → "hi fred!"

object.greet = function (greeting, punctuation) {
  return greeting + "ya " + this.user + punctuation;
};

bound("!");
// → "hiya fred!"
Try It Yourself

How It Works

  1. First call. Uses the original greet.
  2. Swap. object.greet is replaced with a new function.
  3. Second call. Lookup runs again → new body → "hiya fred!".
  4. Why. This is the lazy / late-binding pattern the docs highlight.

Example 3 — Placeholder Slot

Defer the greeting; keep punctuation fixed.

Lodash
var object = {
  user: "fred",
  greet: function (greeting, punctuation) {
    return greeting + "ya " + this.user + punctuation;
  }
};

var bound = _.bindKey(object, "greet", _, "!");
bound("hi");
// → "hiya fred!"
Try It Yourself

How It Works

  1. Slot. _ marks “fill greeting later” (full Lodash build).
  2. Fixed. "!" is already bound as punctuation.
  3. Call. bound("hi") fills the placeholder.
  4. Modular. Use _.bindKey.placeholder instead of _.

Example 4 — bindKey vs bind

After a swap, only bindKey sees the new method.

Lodash
var object = {
  user: "fred",
  greet: function (g, p) {
    return g + " " + this.user + p;
  }
};

var byKey = _.bindKey(object, "greet", "hi");
var byFn = _.bind(object.greet, object, "hi");

object.greet = function (g, p) {
  return g + "ya " + this.user + p;
};

[byKey("!"), byFn("!")];
// → ["hiya fred!", "hi fred!"]
Try It Yourself

How It Works

  1. bindKey. Re-reads object.greet → new string.
  2. bind. Still holds the old function reference → old string.
  3. Pick. Hot-swap / plugins → bindKey. Stable fn → bind.
  4. this. Both keep this as object when called.

Example 5 — Define the Method Later

Create the wrapper before the method exists.

Lodash
var object = { user: "fred" };
var bound = _.bindKey(object, "greet", "hi");

object.greet = function (greeting, punctuation) {
  return greeting + " " + this.user + punctuation;
};

bound("!");
// → "hi fred!"
Try It Yourself

How It Works

  1. Early. Wrapper is created while greet is missing.
  2. Define. Assign object.greet before calling.
  3. Lookup. First call finds the new method and runs it.
  4. Caution. Calling before the method exists throws (not a function).

Browser & Runtime Support

_.bindKey is a Lodash 4.x Function helper (since 0.10.0). It needs no special browser APIs beyond loading Lodash.

✓ Stable · Lodash 0.10.0+

_.bindKey()

Available in [email protected] full builds and the lodash/bindKey modular import. Works in evergreen browsers and Node / Bun / Deno when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.bindKey Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import bindKey from "lodash/bindKey" for smaller builds.

Frequently Asked Questions

_.bindKey(object, key, ...partials) returns a function that looks up object[key] each time it runs, calls that method with this set to object, and prepends any partials.
bind captures a specific function value when you create the wrapper. bindKey stores the object and key, so replacing object[key] later changes what the wrapper calls.
A sentinel (often _ in the full Lodash build) marking argument slots to fill at call time. In modular imports use bindKey.placeholder.
That is a main use case — create the bound function early, then define or swap object[key] before the first call.
No. It only reads object[key] on each invocation and returns a new wrapper function.
Use import bindKey from "lodash/bindKey" then bindKey.placeholder for deferred slots. Full build: import _ from "lodash" then _.bindKey.

Next: _.curry()

Transform a function so arguments can be supplied across multiple calls.

_.curry() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful