Google Apps脚本重新声明常量错误 [英] Google Apps Script Redeclaration of Const Error

查看:81
本文介绍了Google Apps脚本重新声明常量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下Google Apps脚本脚本:

Given this Google Apps Script script:

'use strict'
const foo = 2;
function bar() {
  Logger.log(foo + 2);
}

运行函数 bar 导致 TypeError:const foo的重新声明。

为什么?如何重新声明 foo

Why? How is foo being redeclared?

推荐答案

似乎是由于参差不齐实施ES6。如果我从函数中删除foo,仍然会收到错误消息,因此该错误来自全局const声明。下面的代码产生相同的错误,但如果注释掉const foo,则不会发生错误。

Seems like it's due to spotty implementation of ES6. I still get the error if I remove foo from the function, so the error is coming from the global const declaration. The below code produces the same error, but no error if you comment out const foo.

const foo = 2;

function bar() {
  const bar = 2;
  Logger.log(bar + 2);
}

请参见 Google Apps脚本Javascript标准支持,尤其是第一个注释。

See Google Apps Script Javascript Standard Support, in particular the first comment.

这篇关于Google Apps脚本重新声明常量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆