Geo*_*tal 10 javascript const google-apps-script
鉴于此Google Apps脚本脚本:
'use strict'
const foo = 2;
function bar() {
Logger.log(foo + 2);
}
Run Code Online (Sandbox Code Playgroud)
运行该函数会bar导致aTypeError: redeclaration of const foo.
为什么?怎么foo被重新宣布?
似乎是因为ES6的执行不力.如果我从函数中删除foo,我仍然会收到错误,因此错误来自全局const声明.下面的代码产生相同的错误,但如果你注释掉const foo则没有错误.
const foo = 2;
function bar() {
const bar = 2;
Logger.log(bar + 2);
}
Run Code Online (Sandbox Code Playgroud)
请参阅Google Apps脚本Javascript标准支持,特别是第一条评论.