var array_of_functions = [
first_function('a string'),
second_function('a string'),
third_function('a string'),
forth_function('a string')
]
array_of_functions[0];这并不能按预期工作,因为数组中的每个函数都是在创建数组时执行的。
执行数组中的任何函数的正确方法是:
array_of_functions[0]; // or, array_of_functions[1] etc.谢谢!
发布于 2020-11-12 03:56:58
使用HTML语法,如果您需要一个类似“管道”的过程,您可以通过一系列函数(在我的例子中,是一个ES6抽象语法树)传递相同的对象,您可以使用for...of来调用给定数组中的每个管道函数:
const setMainElement = require("./set-main-element.js")
const cacheImages = require("./cache-images.js")
const removeElements = require("./remove-elements.js")
let htmlAst = {}
const pipeline = [
setMainElement,
cacheImages,
removeElements,
(htmlAst) => {
// Using a dynamic closure.
},
]
for (const pipe of pipeline) {
pipe(htmlAst)
}https://stackoverflow.com/questions/4908378
复制相似问题