Google apps script 如何将要运行的函数传递给函数?
我必须先检查某个属性是否存在,然后才能运行google电子表格附加菜单中列出的功能。与其为每个函数创建一个相同检查的副本,我希望创建一个函数,可以将该函数作为参数传递给运行。我该怎么做 下面是我的非功能测试代码,但您可能会明白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
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();
}
}