Lodash _.method() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Util utilities

What You’ll Learn

By the end of this tutorial, you’ll build reusable method invokers with Lodash’s _.method()—fix the method path, pass the object later.

01

Core Syntax

_.method(path, ...args)

02

Partial Args

Bind method args at creation time.

03

Map Iteratee

Call the same method on each item.

04

Nested Paths

Dot paths like 'a.b'.

05

vs invoke

Reusable vs one-off call.

06

vs methodOf

Path first vs object first.

What Is _.method()?

_.method() is an invoker factory. You give it a method path (and optional arguments for that method); Lodash returns a function that accepts an object and calls the method on it—with this bound correctly.

💡
Beginner tip — args bind at creation

_.method('greet', 'John')(obj) calls obj.greet('John'). Extra arguments belong in the _.method(...) call, not after the object when you invoke the returned function.

This pattern shines with _.map when every element exposes the same method name—pass _.method('getLabel') as the iteratee instead of writing (item) => item.getLabel() repeatedly.

📝 Syntax

Specify the method path and any arguments to pass through:

javascript
_.method(path, [args])

Syntax Rules

  • path — method path on the target object (string dot-path or key array).
  • args — optional arguments forwarded to the method when the invoker runs.
  • Return value — function (object) => result.
  • this — the method runs with the target object as its context.
  • One-off — use _.invoke(object, path, ...args) when you do not need a reusable invoker.
javascript
import method from "lodash/method";



const obj = {

  greet(name) {

    return "Hello, " + name + "!";

  },

};



const greetJohn = method("greet", "John");



greetJohn(obj);

// "Hello, John!"

⚡ Quick Reference

TaskCode patternNotes
Build invoker_.method('getName')No method args
With method args_.method('add', 10, 5)Bound at creation
Run on objectinvoker(obj)Single object arg
Map iteratee_.map(items, _.method('label'))Per-element call
Nested path_.method('a.b')Deep method
One-off call_.invoke(obj, 'greet', 'A')No factory
Returns
Function

Invoker

Fixes
Path

Method name

Opposite
methodOf

Object first

Category
Util

Invocation

🧰 Parameters

Arguments to _.method() and the invoker it returns:

path Required

Method path on each target object—e.g. 'greet', 'calc.add', or ['calc', 'add'].

_.method("getTotal")
args Optional

Values passed to the method when the invoker runs. Set them here—not as extra parameters on invoker(obj).

_.method("add", 10, 5)
returned fn Invoker

Accepts the target object, resolves path, invokes the method with bound args, returns the method’s result.

const run = _.method("fn", 1)
missing method undefined

If the path is missing or not callable, invoke returns undefined—not a function. Validate before critical calls.

_.method("missing")(obj)

When the object is fixed and the path varies, use _.methodOf() instead.

Examples Gallery

Practical _.method() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.

📚 Getting Started

Basic invokers and runtime method names.

Example 1 — Greet with bound argument

Pass the greeting name when building the invoker.

javascript
const obj = {

  greet(name) {

    return "Hello, " + name + "!";

  },

};



const greetJohn = _.method("greet", "John");



console.log(greetJohn(obj));

// "Hello, John!"
Try It Yourself

How It Works

The old tutorial used greetMethod(obj, 'John'), but Lodash binds 'John' in _.method('greet', 'John'). The invoker receives only the object.

Example 2 — Dynamic method name

Pick add or subtract at runtime, with operands bound upfront.

javascript
const calc = {

  add(a, b) { return a + b; },

  subtract(a, b) { return a - b; },

};



const operation = "+";

const methodName = operation === "+" ? "add" : "subtract";



const mathFunc = _.method(methodName, 10, 5);



console.log(mathFunc(calc));

// add(10, 5) = 15
Try It Yourself

How It Works

Both the method name and its arguments can be chosen before you create the invoker—ideal for strategy-style dispatch tables.

📈 Practical Patterns

Map iteratees, nested paths, and safe invocation.

Example 3 — Map with a shared method

Call the same method on every item in a collection.

javascript
const widgets = [

  { label() { return "A"; } },

  { label() { return "B"; } },

  { label() { return "C"; } },

];



console.log(_.map(widgets, _.method("label")));

// ["A", "B", "C"]
Try It Yourself

How It Works

Each array element becomes the object passed to the invoker—Lodash’s canonical _.method use case.

Example 4 — Nested method path

Invoke a method on a nested object via dot path.

javascript
const items = [

  { api: { fetch: () => "data-A" } },

  { api: { fetch: () => "data-B" } },

];



console.log(_.map(items, _.method("api.fetch")));

// ["data-A", "data-B"]

How It Works

Path resolution matches _.get / _.invoke—traverse nested objects before calling the method.

🚀 Beyond the Basics

Compare with invoke and guard missing methods.

Example 5 — method vs invoke

Reuse a factory vs call once inline.

javascript
const obj = {

  greet(name) { return "Hi, " + name; },

};



const greetAnn = _.method("greet", "Ann");

console.log(greetAnn(obj));           // reusable invoker

console.log(_.invoke(obj, "greet", "Ann")); // one-off equivalent

When to use which

Prefer _.method when passing an invoker to _.map or storing it. Use _.invoke for a single immediate call.

Example 6 — Guard missing methods

Check before invoking—the result is not a function when the path is missing.

javascript
const obj = {

  greet(name) { return "Hello, " + name + "!"; },

};



const unknown = _.method("unknownMethod");

const result = unknown(obj);



console.log(result);

// undefined — not a function



if (typeof _.get(obj, "unknownMethod") === "function") {

  console.log("safe to call");

} else {

  console.log("method missing — skip or fallback");

}

Fix for old error-handling example

The reference incorrectly checked typeof result === 'function'. Missing methods yield undefined from invoke—not another function.

🧠 How _.method() Works

1

Capture path + args

Lodash stores the method path and any arguments to forward.

Setup
2

Return invoker

The new function waits for a target object.

Factory
3

Resolve & invoke

On call, find the method at path and run it with object as this and stored args.

Execute
=

Method return value

Whatever the invoked method returns—or undefined if the path is missing.

📝 Notes

  • Method arguments are bound in _.method(path, ...args), not on invoker(object, ...).
  • The invoker preserves correct this—important for methods that read this internally.
  • Missing paths return undefined; they do not throw by default in Lodash invoke.
  • Use with _.map when each element shares the same method name.
  • For varying paths on one object, use _.methodOf().
  • For per-call arguments without a factory, use _.invoke(object, path, ...args).

Conclusion

_.method() builds reusable invokers that call a method path on whatever object you pass in— with optional arguments bound upfront.

Reach for it in _.map pipelines and dynamic dispatch tables; pair with _.methodOf() when the object is fixed instead of the path.

💡 Best Practices

✅ Do

  • Bind method args in _.method(path, ...args)
  • Use as a _.map iteratee when method names align
  • Store invokers when the same path runs on many objects
  • Validate missing methods before critical workflows
  • Prefer _.invoke for one-off calls

❌ Don’t

  • Pass method args after the object on the invoker call
  • Assume missing methods throw—they often return undefined
  • Check typeof result === 'function' after invoke for existence
  • Use method when path varies but object is fixed—use methodOf
  • Extract methods that rely on this without an invoker or bind

Key Takeaways

Knowledge Unlocked

Five things to remember about _.method()

Use these points when building method invokers.

5
Core concepts
🔗 02

Bind args

At creation.

Mechanics
📊 03

Map

Shared method.

Practical
04

invoke

One-off call.

Compare
05

methodOf

Object first.

Next step

❓ Frequently Asked Questions

_.method(path, ...args) returns a function that takes an object and invokes the method at path on that object, passing any args you supplied when creating the invoker. It is a reusable 'call this method on whatever object I give you' helper.
Arguments after path are bound when you call _.method—not when you call the returned function. Example: _.method('greet', 'John')(obj) calls obj.greet('John'). The returned invoker typically receives only the target object.
_.invoke(object, path, ...args) runs the method once immediately. _.method(path, ...args) returns a function you can reuse across many objects or pass to _.map.
_.method(path) fixes the method path—the object comes later. _.methodOf(object) fixes the object—the path comes later. They are complementary invoker factories.
Yes. _.map(objects, _.method('getLabel')) calls getLabel on each item. Great when every element exposes the same method name.
Lodash invoke returns undefined when the path cannot be invoked—it does not return a function. Guard with a check on the object or wrap in try/catch for critical paths.
Did you know?

Lodash’s classic map example _.map(objects, _.method('a.b')) works because each array element becomes the object argument to the invoker—calling a nested method without writing a lambda per item.

Practice _.method() in the Live Editor

Open the Try It editor, run the examples, and build reusable method invokers.

Open Try It editor →

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.

6 people found this page helpful