且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在库中调用另一个函数时内部函数的语法错误

更新时间:2023-11-24 12:21:16

问题

在Google Apps脚本项目中需要库时,它将在调用脚本的环境。因此,如果调用脚本的运行时不支持该库使用的任何语言功能/语法,则会抛出相应的错误。

When a library is required in Google Apps Script project, it is run in the environment of the calling script. Thus, if any of the language features / syntax used by the library are not supported by the runtime of the calling script, it will throw a corresponding error.

运行时

自GAS从犀牛 V8 运行时是由于尝试使用ES6功能引起的(某些功能甚至在较旧的功能中也受支持,但是自全面检查以来,开发人员的资源列表已被删除)。

One of the most common issues since GAS switched from Rhino to V8 runtime is caused by trying to use ES6 features (some were supported even in the older one, but the comprehensive list is gone from the developers resource since the overhaul).

语法错误

您正在尝试使用旧版运行时不支持的语法,因此 SyntaxError 。该消息直接指向问题(第66行),但未提供有关错误原因的信息,因此混淆是可以理解的(它是有效的ES6语法的事实)。

You are trying to use syntax not supported in the older runtime, hence the SyntaxError. The message points directly to the issue (line 66) but does not provide info on what is wrong, so the confusion is understandable (the fact that it is valid ES6 syntax adds to it).


实际的问题是箭头功能的存在。

检查运行时间

要检查使用了哪个运行时间(除了牌匾位于如果使用脚本编辑器,则在顶部),打开清单文件( appsscript.json )并找到 runtimeVersion 字段,可以设置为 V8或 DEPRECATED_ES5(犀牛)。

To check which runtime is used (apart from the plaque at the top if using script editor), open manifest file (appsscript.json) and find the runtimeVersion field, it will be set to either "V8" or "DEPRECATED_ES5" (Rhino).

较新的脚本一定会使用V8,但是您必须手动迁移较旧的版本,方法是将上述字段设置为 V8 (也可以根据需要降级)或在运行菜单中选择选项。

Newer scripts are guaranteed to use V8, but you have to migrate older ones manually by either setting the abovementioned field to V8 (you can also "downgrade" as needed) or selecting the option in "Run" menu.