(function(){})()
1.是什么?
答:定义了一匿名函数 并且执行!
2.为啥要怎么写?
比如:
写法一:
<head>
<script>
(function(){
var xxx;
function OMG(){}
})()
</script>
</head>
<body
写法二:
<head>
<script>
var xxx;
function OMG(){}
</script>
</head>
写法一 在闭包中 执行后变量会释放空间写法二 变量仍会在整个页面