Reputation: 157
In many pieces of code I saw such expression:
require('babel-polyfill').default;
What does it mean property default, and where I can find all properties that could be applied to babel-polyfill, because I didn't see in Babel official documentation usage of this option.
Upvotes: 0
Views: 51
Reputation: 32066
This is an ES6 module convention, where someone is setting the "default" export of the module to a specific object. In ES6 syntax, it's equivalent to:
import Module from 'babel-polyfill'
which will take the default export from babel-polyfill and put it in your current file as Module
.
And internally in the babel-polyfill library, they are doing
exports.default = { some: 'Object' }
This is different than named exports, where you want to expose specific named things from your library:
exports.someThing = 'value';
...
import { someThing } from 'that-module';
You can console.log
the results of both require('babel-polyfill')
and require('babel-polyfill').default
to see more. However, babel polyfill mainly provides polyfills in the global namespace, and modifies native prototypes like Array, and you don't use anything from it directly. Simply requiring it has side effects that add correct polyfills to the running Javascript environment.
Upvotes: 2