JS自执行函数的几种写法

时间:2023-03-09 06:25:14
JS自执行函数的几种写法

一:整体写在一个括号中

代码如下:

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

二:function函数整体外加括号

代码如下:

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

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

!function Show(){alert("hello");}()
或者
void function Show(){alert("hello");}()