試圖填充一個JS數組一些動畫我做....當我點擊我的內網頁的鏈接出於測試目的,下面的JavaScript函數被調用,當我遇到這個問題跑了:爲什麼我的函數在我將它推到JS數組上時執行?
function testing()
{
var funcArray = [];
var testFunc = function(){console.log("test function");}
funcArray.push(function(){console.log("hello there");});
funcArray.push(testFunc());
}
當這個執行時,我得到「測試功能」出現在JS控制檯,但不是「你好」。爲什麼推送預定義的testFunc會導致輸出,而不是第一次推送時的內聯函數?
刪除功能括號。只推名稱,'funcArray.push(testFunc);' –
因爲您正在使用() –
執行th函數。非常感謝。 – swingMan