Node.JS中的ECMAScript 6模块 [英] ECMAScript 6 modules in Node.JS

查看:120
本文介绍了Node.JS中的ECMAScript 6模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Node.JS v0.11.3声称对ECMAScript 6模块支持标记为 - harmony_modules

Node.JS v0.11.3 claims to have support for ECMAScript 6 modules with the flag --harmony_modules.

我已经尝试过各种例子,例如以下。

I have tried various examples, such as the following.

module math {
    export var pi = 3.141593;
}

在Node.JS中使模块工作的语法是什么?

What is the syntax to get modules working in Node.JS?

推荐答案

V8中的模块实现不完整。当使用--harmony-modules启用解析支持时,实际功能的支持被搁置。原因是因为ES6模块实际工作的规范已经在工程中,但仍未完全解决。

The modules implementation in V8 is incomplete. There's parsing support when enabled with --harmony-modules, but support of the actual functionality was put on hold. The reason for this is because the specification for how ES6 modules will actually work has been in the works and is still not fully nailed down.

Continuum中的实现(链接截止于Crazy Train的答案)可追溯到2012年11月的临时规格,由于ES6模块规格的不断变化,现在已经过时了。这就是为什么V8开发者支持模块的开发支持。

The implementation in Continuum (the linked screenshot from Crazy Train's answer) dates back to an interim spec from November 2012 and is now woefully out of date because of the ongoing changes to the ES6 module's spec. This is why the V8 devs put development of support for modules on hold.

似乎模块规范正在接近稳定(尽管我希望我们会看到小的改进一段时间),我认为(至少希望),我们将在未来6个月内看到SpiderMonkey和V8的实施。

It seems like the modules spec is approaching stability (though I expect we'll see small refinements for a while) and I think (hope at least) that we'll see SpiderMonkey and V8 moving forward with implementations over the next 6 months.

  • V8 modules bug: https://code.google.com/p/v8/issues/detail?id=1569
  • SpiderMonkey modules bug: https://bugzilla.mozilla.org/show_bug.cgi?id=harmony%3Amodules

这篇关于Node.JS中的ECMAScript 6模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆