Модное слово

  • скрытое состояние: как объект, как частная переменная
var createCounter = function (n){
  let count = n;
  return function(){
    return count++;
  };
};


class Counter{
  constructor(n){
    this.n=n;
  }
  // define the increment method
  increment(){
    // increase the value before returning
    return ++this.n;
  }
}

const counter = Counter(10);
counter.increment();