JavaScript: ECMAScript 5 Usage in Legacy Browsers

ECMAScript 5 (ES5) brings with it some nice improvements. The only problem is that only newer browsers (Internet Explorer 9, Firefox 4, Chrome 5, Safari 5) support it, or at least its most interesting parts.

es5-shim provides a possible solution.

In version v4.5.9, it includes two files es5-shim.js and es5-sham.js.

  • es5-shim.js is monkey-patch a JavaScript context to contain all EcmaScript 5 methods that can be faithfully emulated with a legacy JavaScript engine.
  • es5-sham.js is monkey-patch other ES5 methods as closely as possible. For these methods, as closely as possible to ES5 is not very close.

Note: es5-sham.js requires es5-shim.js to be able to work properly.

You can also find a list of other polyfills here

ECMAScript 5 Compatibility Table can be used to find out what browser you need the shim. When in doubt, just include it, as it auto-detects whether your browser is too old or not.

Example of applying ES compatability shims in a browser project