閱讀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  時間因素與優質自然外鏈的探討