javascript 是否有标准化的 ES6 文件扩展名?如果是,那是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31461026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:50:58  来源:igfitidea点击:

Is there a standardized ES6 file extension? If so, what is it?

javascriptecmascript-6

提问by CaptSaltyHyman

I'm wondering if there's a standardized file extension for ES6 yet. So far I've seen .es6and .es6.jsas two options, but I'm curious if one is generally better supported by third party packages and tools. And if Mozilla is leaning a particular direction.

我想知道 ES6 是否有标准化的文件扩展名。到目前为止,我已经看到了.es6.es6.js作为两种选择,但我很好奇第三方软件包和工具是否通常更好地支持其中一种。如果 Mozilla 偏向一个特定的方向。

回答by kamituel

There's no formal ES6/JS extension, although majority of people seem to prefer .js. ECMAScript specific suffixes aren't common.

没有正式的 ES6/JS 扩展,尽管大多数人似乎更喜欢.js. ECMAScript 特定的后缀并不常见。

Mozilla is using two extensions within Firefox and FirefoxOS: .jsand .jsm. No ECMA Script specific suffixes.

Mozilla 在 Firefox 和 FirefoxOS 中使用了两个扩展:.js.jsm. 没有 ECMA 脚本特定的后缀。

For Gecko (the layout engine written largely in JS), they use both .jsand .jsm. Example: one of the DOM modules source code.

对于 Gecko(主要用 JS 编写的布局引擎),它们同时使用.js.jsm. 示例:DOM 模块源代码之一

In some other subprojects, such as Gaia, they use .jsonly. Example: "system" app for Firefox OS.

在其他一些子项目中,例如Gaia,他们.js只使用。示例:Firefox OS 的“系统”应用程序

Note:.jsmis something specific to Gecko - it's a Javascript module.

注意:.jsm是 Gecko 特有的东西 - 它是一个Javascript 模块

Note:ECMAScript 6 is a standard that is later implemented in Firefox as Javascript. So those two terms are closely related, and are almost synonyms (source).

注意:ECMAScript 6 是一个标准,后来在 Firefox 中作为 Javascript 实现。所以这两个术语密切相关,几乎是同义词(source)。

Heads up: source code on the Gecko side has the syntax that is plain JS with some extensions - some of which ended up in ECMA Script 6, some not. In general, though, Mozillians tend to follow ECMA Script spec closely. Possible differences are listed here.

注意:Gecko 端的源代码具有带有一些扩展的纯 JS 语法 - 其中一些最终出现在 ECMA Script 6 中,有些则没有。不过,总的来说,Mozillians 倾向于密切遵循 ECMA Script 规范。此处列出可能的差异。

回答by Emmington

The response above is good advice. In addition, my understanding is that NodeJS are contemplating the use of the .mjsa.k.a the Michael Hymanson Scriptfile extension, similar to the .jsmfile extension mentioned above.

上面的回答是很好的建议。另外,我的理解是 NodeJS 正在考虑使用.mjsaka Michael Hymanson Script文件扩展名,类似于.jsm上面提到的文件扩展名。

A link to the apparently official discussion: https://github.com/nodejs/node-eps/issues/13

显然是官方讨论的链接:https: //github.com/nodejs/node-eps/issues/13

I will also declare my personal bias is that .jsshould refer to files without modules, and .esshould refer to files with modules.

我还要声明我个人的偏见是.js应该引用没有模块的文件,而.es应该引用带有模块的文件。

I intended this to be a comment to the above rather than a standalone response

我打算这是对上述内容的评论,而不是独立的回应