DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > es6-shim – ECMAScript 6 functionality on ECMAScript 5

es6-shim – ECMAScript 6 functionality on ECMAScript 5

Axel Rauschmayer user avatar by
Axel Rauschmayer
·
Dec. 28, 11 · Web Dev Zone · Interview
Like (0)
Save
Tweet
3.65K Views

Join the DZone community and get the full member experience.

Join For Free
Paul Miller’s es6-shim gives you functionality that will be in ECMAScript 6 (code-named ECMAScript.next), 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.

A few highlights:

  • Strings
        > "hello world".startsWith("hello")
        true
        > "hi".repeat(3)
        'hihihi'
    
  • Object.getOwnPropertyDescriptors() – makes Object.create() more useful.
        var copy = Object.create(Object.getPrototypeOf(orig),
            Object.getOwnPropertyDescriptors(orig));
    
        var newFoo = Object.create(FooProto,
            Object.getOwnPropertyDescriptors({
                instanceProp1: 123,
                instanceProp2: "abc"
            }));
    
  • Object.is() – an improved version of === (which will likely become an operator called is in ECMAScript 6).
        > 0 === -0
        true
        > Object.is(0, -0)
        false
        > NaN === NaN
        false
        > Object.is(NaN, NaN)
        true
    
  • Map – gives you a dictionary with arbitrary keys.
        > var m = new Map();
        undefined
        > m.set("1", "foo");
        undefined
        > m.set(1, "bar");
        undefined
        > m.get("1")
        'foo'
        > m.get(1)
        'bar'
    
    "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!
        undefined
    
  • Easy install on Node.js (you must run at least Node.js 0.6.5!):
        npm install es6-shim
    
    Afterwards, you enable it in your project like this:
        require("es6-shim");
    

Take a look at the tests to get usage examples.

 

Source: http://www.2ality.com/2011/12/es6-shim.html

ECMAScript

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What I Miss in Java, the Perspective of a Kotlin Developer
  • Major PostgreSQL Features You Should Know About
  • Monolith vs Microservices Architecture: To Split or Not to Split?
  • The Power of Enum: Make Your Code More Readable and Efficient [Video]

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo