您的位置:首页 > Web前端 > JavaScript

JS自执行函数的几种写法

2015-10-28 14:19 375 查看
一:整体写在一个括号中

代码如下:

(function Show(){alert("hello");}())


二:function函数整体外加括号

代码如下:

(function Show(){alert("hello");})()


三:function前加一元运算符或者“void”

!function Show(){alert("hello");}()
或者
void function Show(){alert("hello");}()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: