可能重复:
What do parentheses surrounding a JavaScript object/function/class declaration mean?
为什么以下代码不起作用
function func() {
document.writeln("HELLO");
}();
更新:
为什么以下示例O不应该在“function {}”周围使用parentesis?
var v = function() {
return "HELLO";
}();
document.writeln(V);
答案 0 :(得分:4)
使用此:
function func() {
document.writeln("HELLO");
}
func();
或者这个:
(function() {
document.writeln("HELLO");
})();
答案 1 :(得分:1)
尝试:
(function() {
document.writeln('HELLO');
})();