问题描述
是否可以链接"功能?说,我有一个serverclickhandler,然后想立即调用另一个函数.我该怎么办?
Is it possible to 'chain' functions? Say, I have a serverclickhandler and then would like to invoke another function after it right away. How do I go about it?
谢谢.
推荐答案
要在第一个处理程序之后执行第二个处理程序,您只需直接从第一个处理程序中调用它即可,例如
To have a second handler executed after the first one you just need to call it directly from your first handler, e.g.
var app = null;
function firstHandler(e) {
if( app == null )
app = UiApp.getActiveApplication();
//do your thing
//now, instead "return app;" you return the second handler
return secondHandler(e);
}
function secondHandler(e) {
if( app == null )
app = UiApp.getActiveApplication();
//do your job
return app;
}
我将app
var放在了全局范围内,这样您就可以仅在必要时获取它(在函数之间共享而不显式传递它),从而节省了可能代价高昂且未知的行为(至少对我而言) getActiveApplication()
通话.
I placed the app
var on a global scope so you can get it only when necessary (sharing it between the functions without explicit passing it), saving a possibly costly and unknown behavior (to me at least) of a second getActiveApplication()
call.
这篇关于GAS是否提供“链接"功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!