node.js 支持什么版本的 Javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5139168/
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
What version of Javascript is supported in node.js
提问by emtrane
I'm getting started with Node.js and I'm having a hard time figuring out what version of JavaScript is supported by node which makes it difficult figuring out what features I can use. Here's what I know.
我刚开始使用 Node.js,我很难弄清楚 node 支持哪个版本的 JavaScript,这使得我很难确定我可以使用哪些功能。这是我所知道的。
- Nodeuses V8
- V8implements ECMAScript as specified in ECMA-262, 3rd edition
- ECMA-262, 3rd edition is JavaScript 1.5
- 节点使用 V8
- V8实现了 ECMA-262,第 3 版中指定的 ECMAScript
- ECMA-262,第 3 版是JavaScript 1.5
Given this, I would assume I can use JavaScript 1.5 compatible code in node. However, it turns out I can use the Array.forEach
, among other constructs, even though according to MDC it isn't available until Javascript 1.6 -- ECMA-262, 5th edition.
鉴于此,我假设我可以在 node.js 中使用 JavaScript 1.5 兼容代码。但是,事实证明我可以使用Array.forEach
, 以及其他构造,即使根据 MDC 它在 Javascript 1.6 -- ECMA-262,第 5 版之前不可用。
Where am I going wrong? Is there a document somewhere that details the available language features?
我哪里错了?是否有详细说明可用语言功能的文档?
采纳答案by Benson
This matrix(V8 follows the WebKit column fairly closely) seems to pretty well answer the question "what features can I use?" but I can't find a canonical answer to "what version of javascript is supported?" As far as I can tell, the best answer is this: ECMA-262 3rd edition is supported, but many features of the 5th edition are also supported.
这个矩阵(V8 非常接近于 WebKit 专栏)似乎很好地回答了“我可以使用哪些功能?”的问题。但我找不到“支持什么版本的javascript?”的规范答案。据我所知,最好的答案是:支持 ECMA-262 第 3 版,但也支持第 5 版的许多功能。
There's a good explanation of why V8 follows the WebKit and JavaScriptCore functionality on this thread.
有一个很好的解释为什么 V8 在这个线程上遵循 WebKit 和 JavaScriptCore 功能。
回答by John Middlemas
The Node javascript version depends on which version of v8 that Node uses. Node version 0.5.1 (14 Jul 2011) and upwards use v8 3.4.10 or later, and are 5th edition ECMA-262, rather than 3rd Edition. 5th edition is equivalent to Javascript 1.8.5. See below reasons.
Node javascript 版本取决于 Node 使用的 v8 版本。节点版本 0.5.1(2011 年 7 月 14 日)及更高版本使用 v8 3.4.10 或更高版本,并且是第 5 版 ECMA-262,而不是第 3 版。第 5 版相当于 Javascript 1.8.5。请参阅以下原因。
Between 21 May 2011 and 15 June 2011 the v8 website stopped listing v8 as implementing 3rd edition ECMA-262 and started showing 5th edition. http://web.archive.org/web/20110521053630/http://code.google.com/p/v8/http://web.archive.org/web/20110615102350/http://code.google.com/p/v8/
2011 年 5 月 21 日至 2011 年 6 月 15 日期间,v8 网站停止将 v8 列为实施第三版 ECMA-262 并开始显示第 5 版。 http://web.archive.org/web/20110521053630/http://code.google.com/p/v8/http://web.archive.org/web/20110615102350/http://code.google。 com/p/v8/
According to the v8 changelog, on the 15 June 2011 v8 changed to version 3.4.4. So that version and later are 5th edition.
根据 v8 更改日志,2011 年 6 月 15 日 v8 更改为版本 3.4.4。所以那个版本和以后的版本是第 5 版。
According to the Node changelog, v8 3.4.10 was in Node Version 0.5.1, 14 Jul 2011, so that version and later are 5th edition ECMA-26. This does not mean that v8 versions before 3.4.10 were purely 3rd edition though, since there may have been a steady transition from 3rd to 5th through many v8 versions.
根据 Node 更新日志,v8 3.4.10 在 Node 版本 0.5.1 中,2011 年 7 月 14 日,因此该版本及更高版本是第 5 版 ECMA-26。不过,这并不意味着 3.4.10 之前的 v8 版本纯粹是第 3 版,因为许多 v8 版本可能已经从第 3 版到第 5 版稳定过渡。
回答by Nate Whittaker
Looks like, at some point, node.greenwas created to track JavaScript feature support against different Node versions.
看起来,在某些时候,创建node.green是为了跟踪针对不同 Node 版本的 JavaScript 功能支持。
回答by Eric Leschinski
It seems as though we have been reduced to two strategies to figure out which version of Javascript node uses:
似乎我们已经减少到两种策略来确定使用哪个版本的 Javascript 节点:
Strategy 1:trust in what some document somewhere says, which is wrong in many cases. I haven't found the table which indicates the key-value pairs of which version of node supports which version of ECMAScript.
策略 1:相信某处某个文件所说的内容,这在许多情况下是错误的。我还没有找到表示哪个版本的节点支持哪个版本的ECMAScript的键值对的表。
Strategy 2:guess-and-check.
策略 2:猜测和检查。
Find a feature quoted by ES6 and "see if it fails", something like this:
找到 ES6 引用的一个特性并“看看它是否失败”,如下所示:
el@apollo:~/code$ echo "console.log('blue'.includes('blue'))" > a.js
el@apollo:~/code$ cat a.js
console.log('blue'.includes('blue'))
el@apollo:~/code$ node a.js
/home/el/code/javascript/02/a.js:1
ports, require, module, __filename, __dirname) { console.log('blue'.includes('
^
TypeError: undefined is not a function
at Object.<anonymous> (/home/el/code/javascript/02/a.js:1:82)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
el@apollo:~/code$ babel-node a.js
true
I suppose the "babel" here is a reference to the Tanakh. What features does our version of node support? Well, I don't know, you'll have to manually test it. This is going to become a giant MESS. And worse, it seems to be on purpose.
我想这里的“巴别塔”是对塔纳赫的引用。我们的节点版本支持哪些功能?好吧,我不知道,你必须手动测试它。这将成为一个巨大的混乱。更糟糕的是,这似乎是故意的。