小编Nic*_*ick的帖子

Javascript函数数组

var array_of_functions = [
    first_function('a string'),
    second_function('a string'),
    third_function('a string'),
    forth_function('a string')
]

array_of_functions[0];
Run Code Online (Sandbox Code Playgroud)

这不能按预期工作,因为数组中的每个函数都是在创建数组时执行的.

通过执行以下操作来执行数组中任何函数的正确方法是什么:

array_of_functions[0];  // or, array_of_functions[1] etc.
Run Code Online (Sandbox Code Playgroud)

谢谢!

javascript arrays function

116
推荐指数
7
解决办法
16万
查看次数

标签 统计

arrays ×1

function ×1

javascript ×1