GAS:问题在函数中使用全局变量(GAS: Problems in using global var

2019-10-17 04:10发布

我尝试使用我的功能一个全局变量,见下文。 我可以使用全局变量在我FUNC1存储的值,防爆。 77,OK。 在FUNC2我尝试使用存储在全局变量的当前值,但结果是不确定的。

任何意见如何得到这个工作?

doGet() {
    ...
    var buttonValue;
    ...

func1(e,buttonValue) {
    ...
    buttonValue = size;
    throw buttonValue;
    --> buttonValue ok!
    ...
}

func2(e,buttonValue) {
    ...
    throw buttonValue;
    --> buttonValue undefined!
}

Answer 1:

你不能这样做。 全局变量的值不能在处理函数等用途被改变CacheService到具有全局范围存储值

下面是一个代码示例:

function func1(){
  CacheService.getPrivateCache().put('var_name', 'var_value');
}

function func2(){
  var var_value = CacheService.getPrivateCache().get('var_name');
}


文章来源: GAS: Problems in using global variables in functions