Lodash _.functionsIn() method
What you’ll learn
- How
_.functionsIn(object)returns function names from own and inherited enumerable string keys. - Why
_.functionsInsees constructor/prototype-assigned methods, but not non-enumerable ES class methods. - How it differs from
_.functions, which only reports own methods. - Try each example in the editor (
?tryit=1,2,3) with Lodash from a CDN.
Prerequisites
Review _.functions() first. The In suffix means inherited enumerable keys are included.
- Enumerable matters: inherited methods must be enumerable to appear.
- Class syntax caveat: ES class methods are non-enumerable on the prototype, so they usually do not show up.
Overview
_.functionsIn scans an object and its prototype chain, keeps enumerable string-keyed properties whose values are functions, and returns their names in Lodash key iteration order. It is useful for old constructor/prototype APIs, mixins, and objects whose inherited methods are deliberately public.
Own + inherited
Unlike _.functions, inherited enumerable function names are included.
Key-order names
The returned array follows Lodash key iteration; sort it explicitly for documentation or snapshot tests.
Enumerable only
Prototype traversal does not mean all methods. Non-enumerable class methods remain hidden.
Syntax
_.functionsIn(object) - object: object to inspect, including its prototype chain.
- Returns: an array of own and inherited enumerable function property names.
- Does not include: non-enumerable methods or symbol-keyed methods.
Include enumerable prototype methods
Methods assigned directly to a constructor’s prototype are enumerable by default, so _.functionsIn includes them.
import functionsIn from "lodash/functionsIn";
function Animal(name) {
this.name = name;
}
Animal.prototype.sayHello = function () {
return `Hello, I'm ${this.name}!`;
};
const dog = new Animal("Buddy");
functionsIn(dog);
// -> ["sayHello"] functions vs functionsIn
_.functions reports only own methods. _.functionsIn includes enumerable methods inherited from prototypes too.
import functions from "lodash/functions";
import functionsIn from "lodash/functionsIn";
function Plugin() {
this.setup = function () {};
}
Plugin.prototype.run = function () {};
Plugin.prototype.stop = function () {};
const plugin = new Plugin();
functions(plugin);
// -> ["setup"]
functionsIn(plugin);
// -> ["setup", "run", "stop"] ES class methods are non-enumerable
This is the easy mistake: functionsIn walks the prototype chain, but it still respects enumerability. ES class methods are non-enumerable, so they do not appear.
import functionsIn from "lodash/functionsIn";
class MathOperations {
add(a, b) { return a + b; }
subtract(a, b) { return a - b; }
}
const math = new MathOperations();
functionsIn(math);
// -> []
// ES class methods are inherited, but they are non-enumerable.
Object.keys(MathOperations.prototype);
// -> [] 📋 _.functionsIn vs _.functions vs reflection helpers
| Topic | _.functionsIn | _.functions | Reflect.ownKeys + filtering |
|---|---|---|---|
| Own enumerable functions | Yes | Yes | Manual |
| Inherited enumerable functions | Yes | No | Manual prototype walk |
| Non-enumerable class methods | No | No | Yes, if you inspect descriptors |
| Symbol-keyed methods | No | No | Yes |
| Result order | Lodash key order | Lodash key order | Your code decides |
Use _.functionsIn for enumerable mixin-style APIs. Use reflection helpers when you need complete class/introspection coverage.
Pitfalls to avoid
Expecting ES class methods to appear
They are non-enumerable. _.functionsIn(new MyClass()) often returns [], even though methods exist on the prototype.
Including more than your public API
Inherited enumerable helper methods from mixins or prototypes may be included. Filter by an allow-list before exposing or invoking names from untrusted objects.
Do not infer API priority from order
The returned array follows key iteration across own and inherited properties. Sort or provide an allow-list when order matters.
Returns names, not callable references
Map back carefully: functionsIn(obj).map((name) => obj[name]). Preserve this when invoking methods.
❓ FAQ
Summary
- Purpose: return names of own and inherited enumerable function properties.
- Remember: inherited does not mean non-enumerable; ES class methods are usually hidden from this helper.
- Next: Lodash _.get(), _.functions(), or the official Lodash docs for _.functionsIn.
_.functionsIn walks up the prototype chain, but it still only sees enumerable function properties. Methods created with ES class syntax are non-enumerable, so they will not show up unless you define or expose them differently.
6 people found this page helpful
