<html>
<body>
<script>
c=function(){alert(1); }();//不加括号也可以?
</script>
</body>
</html>c=(function(){alert(1); })();
<body>
<script>
c=function(){alert(1); }();//不加括号也可以?
</script>
</body>
</html>c=(function(){alert(1); })();
单纯的写function(){....}();是不会执行的
还有比较有意思的写法
!function(){}();
~function(){}();
也是会执行的
c=(function(){alert(1); })(); 这种情况少了最后的括号是不对的!不会出现希望的结果
-------------
c=function(){alert(1); }();//相当于定义函数C 并调用他
等同于
c=function(){alert(1); };
c();
后面这句不对,根据运算符优先级可以看出,C并不会等于function(){alert(1); };,它的值是匿名函数function(){alert(1); }的运行结果,由于此函数未指定返回值,所以结果会是undefined
alert(c); // function() {alert(1);}c = function() {alert(2);}();
alert(c); // undefined
实验结果不言自明