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.
Fundamentals
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.
Foundation
📝 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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.method()
Use these points when building method invokers.
5
Core concepts
🛠01
Invoker
Path fixed.
Basics
🔗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.