ES2015
The js
Mix method applies the Babel plugin to Webpack, ensuring that any ES2015 code is transpiled down to browser-friendly ES5 before it's added to the bundle file.
We wrote the Vuebnb frontend app prototype using only ES5 syntax, as we ran it directly in the browser without any build step. But now we can take advantage of ES2015 syntax, which includes a lot of handy features.
For example, we can use a shorthand for assigning a function to an object property.
resources/assets/js/app.js
:
escapeKeyListener: function(evt) { ... }
Can be changed to this:
escapeKeyListener(evt) { ... }
There are several instances of this in app.js
that we can change. There aren't any other opportunities for using ES2015 syntax in our code yet, though in the coming chapters we'll see more.
Polyfills
The ES2015 proposal includes new syntax, but also new APIs, such as Promise
, and additions to existing APIs, such as Array
and Object
.
The Webpack Babel plugin can transpile ES2015 syntax, but new API methods require...