[英]Is there any way in javascript to call multiple functions by name and get their result in array format?
For example if i have 例如,如果我有
fun1(){}
fun2() {}
fun3() {}
these function not having any http calls or not any db operations in them 这些函数中没有任何http调用或没有任何db操作
call the function [fun1,fun2,fun3] and get their result in some array format by using some module like lodash or some thing else 调用函数[fun1,fun2,fun3]并通过使用诸如lodash之类的模块或其他方式以某种数组格式获取结果
Here's an example with three functions that each return a value. 这是一个示例,其中包含三个分别返回值的函数。 You can store the functions in an array and
map
to a results
array: 您可以将函数存储在数组中并
map
到results
数组:
const a = () => 1; const b = () => 2; const c = () => "a"; const funcs = [a, b, c]; const results = funcs.map(e => e()); console.log(results);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.