简体   繁体   中英

How does just importing `babel-polyfill` allow for usage of ES6 features?

I am currently using babel-polyfill and webpack to construct a single page application.

However, I can't quite see how a simple import statement allows for polyfilled functionality to be available in the rest of the code. My understanding of ES6 imports is still a bit fuzzy, so perhaps that's the issue.

If import 'babel-polyfill'; is only being used for side effects, how do these side effects make it into the importing file? Isn't the scope on the imported file out of reach?

If import "babel-polyfill"; is only being used for side effects, how do these side effects make it into the importing file?

By mutating the global environment.

Modules are loaded into the same realm, with the same global scope and the same language-defined globals. The polyfill will create new global variables and extend the prototype objects of existing constructors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM