ECMAScript Cookbook
上QQ阅读APP看书,第一时间看更新

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.