简体   繁体   English

Google Apps Script 支持哪个版本的 ECMA-262?

[英]Which Edition of ECMA-262 Does Google Apps Script Support?

According to this thread from the old Google Group, Apps Script is based on ECMA-262 3rd Edition.根据旧 Google Group 的这个帖子,Apps Script 基于 ECMA-262 3rd Edition。

This would seem to be supported by the fact that auto-completion in the editor displays 3rd Edition array functions.编辑器中的自动完成显示第 3 版数组函数这一事实似乎支持了这一点。

However the following code runs perfectly well, which casts doubt on the matter:然而,下面的代码运行得很好,这让人怀疑这个问题:

var array = [
  1,2,3,4,5
];

Logger.log("forEach:");
array.forEach(function (item,idx,arr) {
  Logger.log(item); 
});

Note the use of ECMA-262 5th Edition Array function forEach.注意使用 ECMA-262 5th Edition Array 函数 forEach。

Would someone authoritative mind giving a definitive answer on why this is the case?有权威人士会就为什么会这样给出明确的答案吗? And whether it's safe to rely on all 5th Edition features or a sub-set that have been implemented and seem to work?依赖第 5 版的所有功能或已实施且似乎有效的子集是否安全?

The documentation says that the old runtime is based on Mozilla's Rhino JavaScript interpreter which provides a subset of ECMAScript 5 and is based on 1.6, with a smattering of 1.7 and 1.8. 文档说旧的运行时基于 Mozilla 的 Rhino JavaScript 解释器,它提供了ECMAScript 5 的一个子集,基于 1.6,有 1.7 和 1.8。

The new Apps Script runtime is supported by the V8 runtime with few exceptions like E6 Modules.除了 E6 模块等少数例外, V8 运行时支持新的 Apps 脚本运行时。

From Built-in Google Services来自内置的 Google 服务

Apps Script supports two JavaScript runtimes: the modern V8 runtime and an older one powered byMozilla's Rhino JavaScript interpreter . Apps Script 支持两种 JavaScript 运行时:现代V8运行时和由Mozilla 的 Rhino JavaScript 解释器提供支持的较旧的运行时。

The V8 runtime supports modern ECMAScript syntax and features. V8 运行时支持现代ECMAScript语法和功能。 The Rhino runtime is based on the older JavaScript 1.6 standard, plus a few features from 1.7 and 1.8 . Rhino 运行时基于较旧的JavaScript 1.6标准,以及1.71.8的一些功能。 You can freely choose which runtime to use with your script, but the V8 runtime is strongly recommended.您可以自由选择要与脚本一起使用的运行时,但强烈建议使用 V8 运行时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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