JavaScript匿名自执行函数的三种写法详解

3 min read
  1. 匿名自执行函数:
(function(){
    // code here
})();
  1. 立即调用函数表达式(IIFE):
(() => {
    // code here
})();
  1. 使用逗号操作符:
,(function(){
    // code here
})();
  1. eval 函数:
eval('(function(){/*code here*/})()');