阅读361 返回首页    go 技术社区[云栖]


自执行函数的优点

保护内部变量不受污染

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

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

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

执行 init();

init
handleA
handleB
undefined

执行 handleA();

最后更新:2017-11-08 20:35:32

  上一篇:go  Linux下打造全方位立体监控系统
  下一篇:go  时间因素与优质自然外链的探讨