js(function(){alert(‘’‘)})
function(){alert('sss')}
是個匿名函數。沒有名字。所以沒有辦法調用。
在外面加個括號,就變成了一個值,值的內容是函數的引用。例如
var a = (function(){"nop"})
a 就是對這個函數的引用。有了名字,之后可以調用,例如a()
現在省略了a,直接對()中的值進行調用就出現了()()的形式,第一個括號中是個函數,就是這樣。
如果還不懂,看看下面三段代碼試試:
?
<script>
(function(){
??function a(){
?? ?function b(){}
??}
??alert(typeof a); // a 可見
??alert(typeof b); // b 不可見
})()
</script>
?
?
<script>
(function(){
??function a(){
?? ?function b(){}
alert(typeof b);
??}
??a(); // b 可見
??alert(typeof a); // a 可見
??alert(typeof b); // b 不可見
})()
</script>
?
?
<script>
(function(){
??(function a(){
?? ?function b(){}
alert(typeof b); // b 可見
??})()
??alert(typeof a); // a 不可見
??alert(typeof b); // b 不可見
})()
</script>
轉載于:https://www.cnblogs.com/mengziHEHE/p/3481553.html
總結
以上是生活随笔為你收集整理的js(function(){alert(‘’‘)})的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: postmen 一个接口调用多次
- 下一篇: xfce4快捷键设置