es5-shim and es5-sham are JavaScript libraries designed to provide ECMAScript 5 (ES5) compatibility shims and polyfills for legacy JavaScript engines that lack native support for these features. The current stable version is 4.6.7, which was last published over four years ago (as of early 2022), indicating an extremely slow release cadence and placing the project firmly in maintenance mode, rather than active development. es5-shim.js faithfully emulates many ES5 methods like Array iteration methods, Date.now, and Function.prototype.bind, making them available in older environments. es5-sham.js, on the other hand, provides best-effort shims for features that cannot be fully or faithfully emulated (such as Object.create with property descriptors, Object.freeze, or Object.defineProperty). A key differentiator is its direct monkey-patching of the global JavaScript context, making it suitable for environments without modern transpilation or module bundling, particularly for ensuring compatibility in very old browser environments like Internet Explorer 8.
npm install es5-shimVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load both es5-shim and es5-sham via `require` and verifies that core ES5 features like `Array.isArray`, `Object.keys`, and `Function.prototype.bind` are available and functional, even in environments that might not natively support them.
Ensure `es5-shim.js` is the absolute first script loaded, followed by `es5-sham.js` (if used), before any other application or third-party code. In a browser, this means placing `<script>` tags at the very top of `<head>`.
Carefully review the documentation for each sham you intend to use and understand its limitations. Where possible, refactor code to avoid relying on these less faithful shams, or implement more robust feature detection and fallbacks.
While generally functional, be aware of these specific non-conformities when debugging or writing highly sensitive code that relies on these edge cases of `Function.prototype.bind` behavior.
Avoid using version `4.5.11`. Upgrade to `4.5.12` or later for correct minified files, or use a different `4.5.x` release.
Only include `es5-shim` for target environments that genuinely lack ES5 features. Utilize build tools or feature detection to conditionally load shims only when necessary for specific legacy browser targets.
Avoid using the second argument of `Object.create` or `Object.defineProperty`/`Object.defineProperties` in targeted legacy environments with `es5-sham`. Some shams, like those for `Object.seal` or `Object.freeze`, will silently fail rather than throw an error, so do not rely on their immutability guarantees.
Ensure `es5-shim.js` is loaded as the very first script in your application, before any code that attempts to use ES5 `Array` methods. Verify the script path and loading order.
If encountering `sort` related issues in Safari 11, upgrade `es5-shim` to version `4.5.10` or newer. This fix ensures the shimmed `sort` handles such cases gracefully.