Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
Javascript 如何将参数传递给作为字符串传递给另一个函数的函数?_Javascript_Function - Fatal编程技术网

Javascript 如何将参数传递给作为字符串传递给另一个函数的函数?

Javascript 如何将参数传递给作为字符串传递给另一个函数的函数?,javascript,function,Javascript,Function,我有以下代码: accountSelector.executeInParallel('processAccounts', 'postProcess'); function processAccounts() { return JSON.stringify(syncMasterLists()); } 我希望能够将一个值传递给processAccountsaccounts函数,而不是这个函数 为此,我更改了代码,现在看起来是这样的: accountSelector.executeInPar

我有以下代码:

accountSelector.executeInParallel('processAccounts', 'postProcess');


function processAccounts() {
  return JSON.stringify(syncMasterLists());
}
我希望能够将一个值传递给
processAccounts
accounts函数,而不是这个函数

为此,我更改了代码,现在看起来是这样的:

accountSelector.executeInParallel('processAccounts("DE")', 'postProcess');


function processAccounts(arg) {
  return JSON.stringify(syncMasterLists());
}
不幸的是,在引入更改后,我开始出现以下错误:

找不到函数processAccounts(“DE”)


我无法理解我是否做错了(如果是的话,那么是什么错了),或者这只是无法完成的事情。

为什么不先调用函数并将结果替换为“executeInParallel”方法,如下所示:

var res = processAccounts("DE");
accountSelector.executeInParallel(res, 'postProcess');


function processAccounts(arg) {
  return JSON.stringify(syncMasterLists());
}
我无法理解我是否做错了(如果是,那是什么 错)或者这只是一些不能做的事情

accountSelector.executeInParallel
将函数名作为参数并执行相同的操作,
processAccounts(“DE”)
不是有效的函数名或现有函数的名称

根据,有一种方法可以传递
选项输入
参数

如果由optionalInput指定,则输入将被传递到 函数名指定的函数

在你的情况下,它将是

accountSelector.executeInParallel('processAccounts', 'postProcess', 'DE' );

一些闭包可能会解决您的问题,这取决于
accountSelector.executeInParallel
的实现方式

const accountSelector={
执行并行(前、后){
让结果=评估(预)()
评估(职位)(结果)
}
}
accountSelector.executeInParallel(processAccountsWithArg('Foo'),'postProcess');
函数processAccount(arg){
console.log('processAccount',arg)
返回JSON.stringify({
关键字:“值”
});
}
函数processAccountsWithArg(arg){
返回函数(){
返回进程帐户(arg)
}
}
函数后处理(结果){
console.log('postProcess',result)

}
什么是
accountSelector
,您可以对其进行更改吗?
accountSelector.executeInParallel
如何执行函数@JamesThorpe这是我们的课。和否:(
accountSelector.executeInParallel('processAccounts', 'postProcess', 'DE' );