📜  js 闭包示例 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:35.900000             🧑  作者: Mango

代码示例1
function outer() {
  var counter = 0; // Backpack or Closure
  function incrementCounter() {
    return counter++;
  }
  return incrementCounter;
}

const count = outer();
count(); // 0
count(); // 1
count(); // 2