0

我想了解代码中发生的情况,其中变量没有立即存储,而是在调用之前先执行。示例代码可以是这样的(在全局范围内):

var alertMe = alert("I\'m being executed then stored to be called again, but why?"); 
4

1 回答 1

1

因为您存储的是调用函数的结果,而不是存储函数。

这将是你所追求的:

var alertMe = function () { 
        alert("I\'m being executed then stored to be called again, but why?"); 
    };

然后当你想调用它时:

alertMe();
于 2015-06-10T16:24:05.450 回答