Lodash isFunction Browser and Runtime Compatibility
This article evaluates the reliability and environmental support of
Lodash's _.isFunction method across various JavaScript
runtimes. It covers modern browsers, legacy environments, server-side
platforms, and multi-realm execution contexts like iframes. By examining
how Lodash handles type-checking internally, this guide clarifies where
developers can depend on this utility without encountering typical edge
cases associated with standard JavaScript evaluation.
How Lodash Implements
_.isFunction
In vanilla JavaScript, using typeof value === 'function'
or value instanceof Function can lead to false positives,
false negatives, or runtime crashes in specific environments. For
example, instanceof Function fails across different
execution realms (such as iframes) because each realm possesses its own
prototype chain and global Function constructor.
Lodash implements _.isFunction to normalize these
discrepancies. Under the hood, it primarily verifies that the target
value is an object and checks its internal [[Class]] tag
via
Object.prototype.toString.call(value) === '[object Function]'
(along with checks for [object AsyncFunction],
[object GeneratorFunction], and
[object Proxy]). This ensures that the detection mechanism
remains robust regardless of where the function was instantiated.
Supported Environments and Reliability
Modern Web Browsers
_.isFunction is completely reliable across all modern
web browser engines:
- Chromium-based browsers (Google Chrome, Microsoft Edge, Brave, Opera)
- Gecko (Mozilla Firefox)
- WebKit (Apple Safari for macOS and iOS)
In these environments, _.isFunction accurately
identifies standard function declarations, function expressions, ES6
arrow functions, async functions, and generator functions without any
inconsistencies.
Multi-Realm Contexts (iframes and Popups)
One of the primary benefits of _.isFunction is its
complete reliability within multi-window and iframe architectures. In
these setups, passing a callback function from a child iframe to a
parent window will cause standard instanceof Function
evaluations to return false. Because Lodash inspects the
object's internal string tag rather than constructor inheritance,
_.isFunction correctly identifies functions passed across
different windows and frames.
Server-Side Runtimes
Lodash fully supports all mainstream JavaScript server environments:
- Node.js: Reliably supported across all active and legacy releases (including versions as old as Node 0.10 through modern versions).
- Deno: Fully supported when importing Lodash via npm specifiers or compatible ES module CDNs.
- Bun: Supported out of the box with zero compatibility issues.
Server-side execution avoids DOM-related type quirks, making the check fast and deterministic.
Web Workers and Service Workers
_.isFunction is reliable inside Web Workers, Shared
Workers, and Service Workers. Since workers operate within isolated
threads without a DOM, functions created in these scopes behave
identically to standard ECMAScript functions and are correctly
detected.
Legacy Environments
Lodash was heavily optimized to overcome quirks found in historical and legacy platforms:
- Internet Explorer 9–11: Reliably supported. Lodash resolves historic bugs where certain DOM methods, host objects, or ActiveX objects reported unusual types.
- Older JavaScript Engines: In early versions of V8
or Rhino, regular expressions sometimes returned
'function'under a naivetypeofcheck. Lodash specifically handles this edge case to prevent regular expressions from being incorrectly classified as functions.
Summary of Function Types Handled
Across all supported environments, _.isFunction reliably
returns true for:
- Standard functions (
function () {}) - Arrow functions (
() => {}) - Async functions (
async function () {}) - Generator functions (
function* () {}) - Built-in native methods (e.g.,
Math.round,Array.prototype.push) - Functions instantiated via
new Function()
It consistently returns false for objects, arrays,
regular expressions, primitives, null, and undefined across every
runtime.