为方便起见,我已在线评论了您遇到的一些问题。
function go()
{
var procedures = [];
for (var i = 0; i < 10; i++)
{
procedures[procedures.length] = function ()
{
alert("You are now " + i + " years old");
//this function doesn't return anything, so you will never assign any values to procedures[procedures.length]
}
run_procs(procedures);
}
function run_procs(procs)
{
for (var i = 0; i < procs.length; i++)
{
procs[i]();
//the argument you have passed to this function is not a function itself, so this won't do much.
}
}
//this is inside the go() declaration so you aren't actually calling it.
go();
}
这些代码都不会运行,因为您只是声明了该函数而实际上并未调用它。因此,您不会收到任何错误。