How it works...

The babel-polyfill package, appropriately enough, provides what are known as polyfills. A polyfill fills in the gaps that legacy browsers leave in the ECMAScript spec.

In the previous example, it just so happens that the current version, 61, of Chrome does not implement the Array.prototype.values method. The polyfill code runs before the main function. It looks to see if the values method is implemented on the Array.prototype object. If it isn't implemented natively, then polyfill implements the method. If it is implemented then polyfill leaves the native implementation in place.

In this way, the polyfill library makes a large set of newer methods available.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.