自执行函数的优点

来源:互联网 发布:js 格式化数字 前补零 编辑:程序博客网 时间:2024/04/19 15:26

保护内部变量不受污染

(function() {  function init() {    console.log('init');    handleA();  }  function handleA() {    console.log('handleA');    handleB();  }  function handleB() {    console.log('handleB');  }  window.init = init;}())

执行 init();

inithandleAhandleBundefined

执行 handleA();