我想了解变量未立即存储的代码所发生的情况,而是在调用变量之前先执行。示例代码可以是这个(在全局范围内):
var alertMe = alert("I\'m being executed then stored to be called again, but why?");
答案 0 :(得分:1)
因为您正在存储调用函数的结果,而不是存储函数。
这就是你所追求的:
var alertMe = function () {
alert("I\'m being executed then stored to be called again, but why?");
};
然后当你想打电话时:
alertMe();