(function(){alert('hello')})();来源于油猴脚本
2 回答

慕运维8079593
TA贡献1876条经验 获得超5个赞
这个叫立即执行函数。就相当于functiona(){alert('hello')}a()为什么不直接写成这样呢:alert('hello')这是因为有时候需要开辟新的函数作用域,确保外层变量不被污染;或者在创建一个闭包的时候,代码可以简洁一点。其实。。。没什么用

慕沐林林
TA贡献2016条经验 获得超9个赞
主要是隔离作用域(function(){vara=1;//})();以上例程,a的作用域在function内部,如果没有function包裹,默认会挂载window下
添加回答
举报
0/150
提交
取消