我了解 ES6 模块规范,问题是关于它的支持。 AFAIK,没有浏览器在 native 实现此功能(请参阅浏览器兼容性 here)。对此有几个问题:
- ES6 模块显然是 ES6 的一个特性。当我看 kangax compatibility table ,我根本看不到这样的行(对于 ES6 模块),这是为什么呢?毕竟这是 ES6 的特性...
- 因此,现在使用 ES6 的唯一方法是使用构建工具,例如 babel、browserify 或任何其他替代工具,对吗?
- 当原生支持模块时,如何从浏览器获取异步 AJAX 调用?
最佳答案
ES6 modules is an ES6 feature, obviously. When I look at kangax compatibility table, I don't see such row (for ES6 modules) at all, why is that?
有 an issue being discussed在 kangax 的 github 上。
the only way to use ES6 right now is to use a build tool, such as babel, browserify or any other aternative, right?
没有。 Guy Bedford 在 http://github.com/ModuleLoader/browser-es-module-loader 也有一个 polyfill .
并且已经有原生实现它的 Edge 预览版。
how are the modules gonna be fetched, when they're natively supported - as async AJAX calls from the browser?
是的,但不完全是:它们将在第一次使用时通过调用导入库上的对象(函数或属性)来获取。
关于javascript - es6 模块原生支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39144317/