3
我正在向數組添加一個匿名函數,並試圖迭代該數組執行其內容。即使有一個簡單的測試用例,我也會遇到TypeError:不是函數。將函數添加到數組
我是否缺少一些簡單的東西?
//an array of functions
var signInFunctions = [];
//add a function to the array
signInFunctions.push(function() {
console.log("hello world");
});
function userSignedIn() {
//execute all functions in the signInFunctions array
for (var i = 0; i < signInFunctions.length; i++) {
signInFunctions(i);
}
}
userSignedIn();
這裏的錯誤:
TypeError: 'function() {
console.log("hello world");
}' is not a function (evaluating 'signInFunctions(i)')
您需要'signInFunctions [ i]();' – BenM
嘗試'signInFunctions [i]();' – rab