是“链接”气可用的功能?(Is 'chaining' functions avail

2019-10-31 18:37发布

是否有可能为“链”的功能呢? 我说,我有一个serverclickhandler然后想后调用另一个函数的时候了。 我怎么做呢?

谢谢。

Answer 1:

有你只需要直接从您的第一个处理程序,例如把它的第一个后执行的第二个处理程序

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在全球范围内无功,让你可以只在必要时(职能部门之间共享它没有明确的传递),节省了可能昂贵的和未知的行为(至少对我来说)第二的getActiveApplication()调用。



Answer 2:

不知道我理解你的确切问题,但serverhandlers到你提到的正是该做...( 见DOC )请注意,您可以分配多个处理程序的UI元素来触发不同的功能,并最终把它们连。



文章来源: Is 'chaining' functions available in GAS?