【发布时间】:2021-08-21 22:34:34
【问题描述】:
我最终遇到了一个问题,因为我在函数中声明局部变量时没有使用 var 前缀,所以当它到达下一个函数时,它实际上会自动选择该变量,即使那是一个语法错误,因为我最初的意图是使用另一个具有相似名称的局部变量。那么谷歌应用脚本上是否有设置在函数内的全局变量声明中抛出错误以避免这种棘手的问题?
这是我的问题的示例代码
function f1(){
for(var idx=0;idx<length; idx++){
tmp1 = idx; // since tmp1 missing var, it endup as global variable
...
}
}
function f2(){
Logger.log(tmp1);// even though I did not delcare tmp1 here, it will not throw either validation nor runtime error.
}
【问题讨论】:
-
试试让.........
标签: javascript function google-apps-script global-variables