By the end of this tutorial, you’ll use Lodash’s _.methodOf() to fix an object and invoke different method paths on it at runtime.
01
Core Syntax
_.methodOf(object, ...args)
02
Path Later
Returned fn takes the method path.
03
Partial Args
Bind method args at creation.
04
Dispatch Tables
Pick operation name at runtime.
05
vs method
Object first vs path first.
06
this Binding
Context stays on the object.
Fundamentals
What Is _.methodOf()?
_.methodOf() is the mirror of _.method(). You fix the object upfront; the returned function accepts a method path and calls that method on the object—with correct this binding.
💡
Beginner tip — path goes on the invoker call
_.methodOf(user)('greet') calls user.greet(). Do not write _.methodOf(user, 'greet')—the second argument to methodOf is a method argument, not the path name.
Use this when one instance exposes many operations and you choose the method name dynamically—calculator ops, plugin APIs, or command routers.
Foundation
📝 Syntax
Fix the object (and optional method args); pass the path when you call the invoker:
javascript
_.methodOf(object, [args])
Syntax Rules
object — the target whose methods will be invoked.
args — optional arguments forwarded to the method (bound at creation).
Return value — function (path) => result.
path — method name or dot-path passed to the returned function.
The old tutorial used _.methodOf(user, 'greet') then greetingFunction()—that misplaces the path. The path belongs on the invoker call: invokeOnUser('greet').
Example 2 — Dynamic operation dispatch
One math utils object; pick square or cube at runtime.
this stays on calculator automatically—no manual .call(calculator, …) needed. The old reference’s addFive.call(calculator, 5) pattern was redundant and misused the API.
Using _.has(car, 'startEngine') before building the invoker is fine too. Avoid the old anti-pattern of composing with window.alert via methodOf—it couples code to globals unnecessarily.
Compare
📋 _.methodOf vs related patterns
Topic
_.methodOf
_.method
_.invoke
Direct call
Fixed at creation
Object
Path
All at once
N/A
Passed later
Path
Object
N/A
Per call
Best for
Varying method names
Same method, many objects
One-off
Simple scripts
Map iteratee
Rare
Common
Awkward
Manual loop
Partial args
After object
After path
In invoke call
Manual
🧠 How _.methodOf() Works
1
Capture object + args
Lodash closes over the target object and any method arguments.
Setup
2
Return path invoker
The new function waits for a method path string or key array.
Factory
3
Resolve & invoke
Find the method at path on the fixed object, call with bound args and correct this.
Execute
=
🛠
Method return value
Whatever the invoked method returns—or undefined if the path is missing.
Important
📝 Notes
The method path is not the second argument to _.methodOf—it is the argument to the returned function.
Arguments after object in _.methodOf are forwarded to the method, like _.method.
this is set to the fixed object automatically—no extra .call needed.
Prefer _.method() for _.map(collections, _.method('fn')) patterns.
Missing paths return undefined from invoke—validate dynamic path strings in user-facing dispatchers.
Next in the series: _.mixin() for extending Lodash itself.
Wrap Up
Conclusion
_.methodOf() fixes an object and lets you invoke different method paths on it— the object-first mirror of _.method().
Use it for dispatch tables and plugin APIs; bind operands with partial args and pass the operation name when you call the invoker.
Pass paths to the invoker: invokeOn(obj)('methodName')
Bind method args in _.methodOf(object, ...args)
Validate dynamic paths before dispatch in user-facing APIs
Use for operation routers on a single service instance
Pair with _.invoke for one-off calls
❌ Don’t
Pass the method name as the second arg to _.methodOf
Manually .call the object unless you know why
Use methodOf for map-over-objects—use method instead
Compose with global window methods in tutorials or app code
Assume missing methods throw—they often return undefined
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.methodOf()
Use these points when building object-first invokers.
5
Core concepts
📦01
Object first
Fix instance.
Basics
📂02
Path later
On invoker call.
Mechanics
🔗03
Bind args
At creation.
Partial
🛠04
Dispatch
Runtime paths.
Practical
↔05
method
Mirror helper.
Compare
❓ Frequently Asked Questions
_.methodOf(object, ...args) returns a function that takes a method path and invokes that method on the fixed object, forwarding any args you bound at creation. It is the object-first counterpart to _.method(path, ...args).
The path (method name or dot-path string) as its first argument—not the object. Example: _.methodOf(user)('greet') calls user.greet() with user as this.
Arguments after object in _.methodOf are bound when you create the invoker. Example: _.methodOf(calc, 10, 5)('add') calls calc.add(10, 5).
_.method(path, ...args) fixes the path—the object comes later. _.methodOf(object, ...args) fixes the object—the path comes later. They are mirror-image invoker factories.
No—that treats 'greet' as a method argument, not a path. Use _.methodOf(object)('greet') or _.method('greet')(object). The path is passed to the returned function, not to _.methodOf itself.
Use it when one object exposes several methods and you pick the path at runtime—calculator dispatch tables, plugin registries, or APIs where the target instance is fixed but the operation name varies.
Did you know?
_.methodOf(object, ...args)(path) and _.method(path, ...args)(object) are two views of the same invoke operation—pick whichever side of the call varies in your code.