當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
我去,JS自执行匿名函数竟然有20几种写法!
生活随笔
收集整理的這篇文章主要介紹了
我去,JS自执行匿名函数竟然有20几种写法!
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
發(fā)現(xiàn)一個新的自執(zhí)行寫法:{ var x; x=1; alert(x);} //2013-01-30 14:45:57 //五大類,20幾種寫法//第一類 //最常見的一種 ( function(w) {alert(w.location.href+","+11); }(window));[ function(w) {alert(w.location.href+","+11); }(window) ];//第二類 ~ function(w) {alert(w.location.href+","+11); }(window);! function(w) {alert(w.location.href+","+11); }(window);+ function(w) {alert(w.location.href+","+11); }(window);- function(w) {alert(w.location.href+","+11); }(window);//第三類 delete function(w) {alert(w.location.href+","+11); }(window);typeof function(w) {alert(w.location.href+","+11); }(window);void function(w) {alert(w.location.href+","+11); }(window);new function(w) {alert(w.location.href+","+11); }(window);new function() {alert(window.location.href+","+11); }; //第四類 var f = function(w) {alert(w.location.href+","+11); }(window);//第五類 1, function() {alert(window.location.href+","+11); }();1 ^ function() {alert(window.location.href+","+11); }();1 > function() {alert(window.location.href+","+11); }();1 < function() {alert(window.location.href+","+11); }();1 / function() {alert(window.location.href+","+11); }();1 * function() {alert(window.location.href+","+11); }();1 | function() {alert(window.location.href+","+11); }();1 % function() {alert(window.location.href+","+11); }();1 & function() {alert(window.location.href+","+11); }();
轉(zhuǎn)載于:https://my.oschina.net/pandao/blog/102647
總結(jié)
以上是生活随笔為你收集整理的我去,JS自执行匿名函数竟然有20几种写法!的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: myeclipse 8.5 常用快捷键
- 下一篇: [置顶] 强大的jqu