Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何将要运行的函数传递给函数?_Google Apps Script - Fatal编程技术网

Google apps script 如何将要运行的函数传递给函数?

Google apps script 如何将要运行的函数传递给函数?,google-apps-script,Google Apps Script,我必须先检查某个属性是否存在,然后才能运行google电子表格附加菜单中列出的功能。与其为每个函数创建一个相同检查的副本,我希望创建一个函数,可以将该函数作为参数传递给运行。我该怎么做 下面是我的非功能测试代码,但您可能会明白 function testRun(){ //in practicality this would be an add-on menu test1Check('test1()'); } function test1(){ Logger.log("Functi

我必须先检查某个属性是否存在,然后才能运行google电子表格附加菜单中列出的功能。与其为每个函数创建一个相同检查的副本,我希望创建一个函数,可以将该函数作为参数传递给运行。我该怎么做

下面是我的非功能测试代码,但您可能会明白

function testRun(){
  //in practicality this would be an add-on menu
  test1Check('test1()');
}


function test1(){
  Logger.log("Function Ran");
}


function test1Check(functionToRun){
      var labels = PropertiesService.getDocumentProperties().getProperty('labels');
  var ui = SpreadsheetApp.getUi(); // Same variations.
  if (!labels) {
    var result = ui.alert(
      'You have not yet set up the page for gClassFolders',
      'Would you like to do this now?',
      ui.ButtonSet.YES_NO);
  // Process the user's response.
  if (result == ui.Button.YES) {
    // User clicked "Yes".
    setupGCF();
  } 

  } 
  else { 
    functionToRun;
  }
}
我必须从发送的参数中删除()并将()添加到函数中的变量中

function testRun(){

  test1Check(test1);
}


function test1(){
  Logger.log("Function Ran");
}


function test1Check(functionToRun){
      var labels = PropertiesService.getDocumentProperties().getProperty('labels');
  var ui = SpreadsheetApp.getUi(); // Same variations.
  if (!labels) {
    var result = ui.alert(
      'You have not yet set up the page for gClassFolders',
      'Would you like to do this now?',
      ui.ButtonSet.YES_NO);
  // Process the user's response.
  if (result == ui.Button.YES) {
    // User clicked "Yes".
    setupGCF();
  } 

  } 
  else { 
    functionToRun();
  }
}