How Lodash Supports Internet Explorer 11
The Lodash JavaScript library maintains compatibility with legacy environments like Internet Explorer 11 by adhering to an ECMAScript 5 (ES5) baseline, using internal shims and fallbacks, detecting platform quirks, and avoiding modern browser APIs. Through strict feature detection and defensive coding, Lodash guarantees that its extensive utility toolkit functions uniformly across modern runtimes and legacy browsers without requiring external polyfills.
ECMAScript 5 Baseline Architecture
Modern JavaScript relies heavily on features introduced in ES6
(ES2015) and beyond, such as arrow functions, classes, Map,
Set, and Promise. Internet Explorer 11 only
provides partial, sometimes non-standard support for ES6.
Lodash solves this at the architectural level by targeting ES5 as its
compilation and distribution baseline. The core source code avoids
native ES6 syntax entirely in production builds. Functions, object
prototypes, and variable declarations rely on standard var
and traditional function statements, ensuring the JavaScript engine in
IE11 (Chakra) can parse and execute the code without syntax errors.
Internal Fallbacks and Shims
Rather than relying on global polyfills that alter the global scope, Lodash embeds internal fallbacks for methods that IE11 either lacks or implements inconsistently.
- Collections and Iteration: While modern engines
leverage the iterator protocol (
Symbol.iterator), IE11 lacks complete symbol support. Lodash implements index-based traversal and custom iteration logic that bypasses the need for native iterators. - Missing Object Methods: Where methods like
Object.assignorObject.isare absent in IE11, Lodash provides internal equivalents (such asbaseAssignor custom equality comparisons) that recreate the specification's logic using basic ES5 operations. - Data Structures: Lodash maintains internal
implementations of complex structures, like associative maps or cache
stores, using parallel arrays or plain hash objects rather than
depending on native
MaporWeakMap.
Feature Detection Over User-Agent Sniffing
Lodash does not inspect the browser's User-Agent string
to determine behavior. Instead, it tests the environment at runtime
using feature detection.
During initialization, Lodash runs micro-benchmarks and capability
tests to see if a native method exists and behaves according to
specification. If an environment’s native method produces known
edge-case failures, Lodash defaults to its internal algorithm. For
instance, native Array.prototype.splice or
Array.prototype.indexOf implementations across different
versions of Internet Explorer occasionally exhibited off-spec behavior
with negative indices or sparse arrays; Lodash detects or accounts for
these anomalies directly.
Handling Internet Explorer Quirks and Host Objects
Internet Explorer 11 treats DOM nodes, window objects, and ActiveX
objects as "host objects," which do not strictly adhere to standard
JavaScript prototypal inheritance rules. In IE11, calling methods like
Object.prototype.toString.call() on certain host objects
can yield unexpected results or throw runtime errors.
Lodash employs defensive programming strategies to address these quirks:
- Host Object Detection: It employs safety checks to determine if an entity is a plain object, a DOM node, or an exotic host object before inspecting its properties.
- The JScript
DontEnumBug: Historically, older IE engines suffered from bugs where shadowed properties that matched non-enumerable prototype properties (liketoStringorvalueOf) were skipped infor...inloops. Lodash retains historical workarounds for property enumeration to ensure consistent key extraction across legacy edge cases. - Safe Property Access: Lodash relies on strict
try/catchwrappers and null-safe internal helpers when accessing properties that might throw security or type errors in IE11's document model.
Comprehensive Cross-Browser Test Matrix
Lodash has historically sustained this compatibility through an automated testing pipeline executed against real browsers via tools like Sauce Labs. Every release of Lodash v4 ran thousands of unit tests directly inside Internet Explorer instances, catching regressions in type checking, coercion, and performance specific to IE11's JavaScript engine.