简体   繁体   English

javascript中有没有办法按名称调用多个函数并以数组格式获取结果?

[英]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: 您可以将函数存储在数组中并mapresults数组:

 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.

相关问题 [JavaScript]有没有办法并行执行多个功能? - [JavaScript]Is there any way to excute multiple functions in parallel? JavaScript中是否可以使用字符串格式的名称来调用在另一个函数范围内声明的函数? - Is there any way in JavaScript to call a function declared inside the scope of another function by using its name available in string format? 有什么方法可以用 JavaScript 更改多个标签? - is there any way to get multiple tags changed with JavaScript? 从Javascript中的onclick调用多个函数的最佳方法是什么 - What is the best way to call multiple functions from an onclick in Javascript JavaScript:连续调用多个异步函数的更好方法? - JavaScript: A better way to call multiple async functions in a row? 有没有办法用 asin/acos/atan 函数 JavaScript 获得弧度? - Is there any way to get radians with asin/acos/atan functions JavaScript? 有没有办法一次在JavaScript中多次调用函数? 使用木偶 - Is there any way to call a function in JavaScript multiple times at once? Using puppeteer 有没有办法在 JavaScript 中命名箭头函数? - Is there a way to name arrow functions in JavaScript? Javascript:有没有办法命名提交函数? - Javascript: Is there a way to name submit functions? Javascript:从多个具有相同名称的变量中获取最后结果 - Javascript: Get last result from multiple vars with same name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM