为什么变量立即执行 window 对象而不是存储它?

Why does the variable executes the window object right away and not store it instead?

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

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

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

这就是您想要的:

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

然后当你想调用它时:

alertMe();