试图填充一个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