Google Apps Script Redeclaration of Const Error

前端 未结 2 2262
失恋的感觉
失恋的感觉 2021-02-20 08:47

Given this Google Apps Script script:

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

Running the function bar

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-20 09:19

    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);
    }
    

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

提交回复
热议问题