如何在一个函数中更改glob以在另一个函数中查看它? [英] How change glob in one function to see it in another function?

查看:57
本文介绍了如何在一个函数中更改glob以在另一个函数中查看它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

英语不是我的母语,对我的错误很抱歉



这是我真正的问题

  var k = 2; 
var m;

函数onOpen(){//事件 - 打开电子表格
m = 5;


function onEdit(){//事件 - 编辑电子表格
var n = k; // k = 2
var p = m; // p = undefine(为什么?)
}




  • 为什么p是不确定的?

  • 为什么 m 在函数 onEdit != 5?

  • 如何在函数 onOpen 中更改 m ,然后使 p = m (= 5)?



  • 为什么m在函数onEdit!= 5?


  • GAS内部实例并在每次调用函数时初始化代码,即在电子数据表打开时调用 onOpen 函数,GAS实例的代码, m 变量等于5。调用 onEdit 函数并且GAS创建一个新的代码实例,在这种情况下, onOpen 函数是 被调用,默认情况下 m 变量等于 undefined ,并且该值被分配到 p



    • 如何在onOpen函数中更改m,然后使p = m(= 5)?

    要实现它,您必须使用中间服务,例如缓存 ScriptDB 服务。


    English is not my native language, big sorry for my mistakes

    Here is my real problem

    var k = 2;
    var m;
    
    function onOpen(){ // on event - Open spreadsheet
        m = 5;
    }
    
    function onEdit(){ // on event - Edit spreadsheet
        var n = k; // k = 2
        var p = m; // p = undefine (why?)
    }
    

    • Why p is undefined?
    • Why is m in function onEdit != 5?
    • How can I change m in function onOpen and then make p = m (= 5)?

    解决方案

    • Why p is undefined?
    • Why is m in function onEdit != 5?

    The GAS internals instances and initializes the code every time a function is called, i.e. the onOpen function is called during a spreadsheet is opened, GAS instances the code, the m variable is equal to 5. After that the onEdit function is called and the GAS creates a new instance of the code, in this instance the onOpen function is not called and the m variable is equal to undefined by default and this value is assigned to the p.

    • How can I change m in function onOpen and then make p = m (= 5)?

    To achieve it, you have to use intermediate services like the Cache or the ScriptDB Services.

    这篇关于如何在一个函数中更改glob以在另一个函数中查看它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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