Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我经常看到这两种约定,我想知道是否存在实际差异。
(function () { document.write("it works"); }()); (function () { document.write("it also works"); })();
两者之间没有区别,左大括号用作语法提示,告诉解析器后面是函数表达式而不是函数声明。
更多http://jsperf.com/self-invoking-function