Black lives matter
Portrait Dr. Axel Rauschmayer
Dr. Axel Rauschmayer
Homepage | Twitter
Cover of book “JavaScript for impatient programmers”
Book, exercises, quizzes
(free to read online)
Cover of book “Deep JavaScript”
Book (50% free online)
Cover of book “Tackling TypeScript”
Book (first part free online)
Logo of newsletter “ news”
Newsletter (free)

es6-shim – ECMAScript 6 functionality on ECMAScript 5

[2011-12-27] esnext, dev, javascript, jslang
(Ad, please don’t block)

Update 2012-03-13: Added a section on installation.

Paul Miller’s es6-shim gives you functionality that will be in ECMAScript 6 (code-named, on ECMAScript 5 engines. It was initially based on a project of mine, but adds much new functionality, Node.js compatibility, and (not least) tests.


The following are a few highlights. Take a look at the tests to get more usage examples.
  • Strings
        > "hello world".startsWith("hello")
        > "hi".repeat(3)
  • Object.getOwnPropertyDescriptors() – makes Object.create() more useful.
        var copy = Object.create(Object.getPrototypeOf(orig),
        var newFoo = Object.create(FooProto,
                instanceProp1: 123,
                instanceProp2: "abc"
  • – an improved version of === (which will likely become an operator called is in ECMAScript 6).
        > 0 === -0
        >, -0)
        > NaN === NaN
        >, NaN)
  • Map – gives you a dictionary with arbitrary keys.
        > var m = new Map();
        > m.set("1", "foo");
        > m.set(1, "bar");
        > m.get("1")
        > m.get(1)
    "1" and 1 are (coerced to) the same key with arrays. Note that each object is considered different from any other object. Hence, the following map entry cannot be easily retrieved:
        > m.set({}, "hello");
        > m.get({})  // new object!


You can either load es6-shim.js as a script in a browser or install it via npm on Node.js (requires at least version 0.6.5):
    npm install es6-shim
Afterwards, you enable it in your project like this:
And you can play with it on the Node.js REPL, with the option of enabling it by default [2].

Related posts

  1. the “TXJS” update by Eich [what will be in ECMAScript 6, code-named]
  2. Execute code each time the Node.js REPL starts