I\'m trying to use a static variable in es6. I\'d like to declare a static variable count in Animal class and increase it. However, I couldn\'t declare
you can use closures to simulate static variables
const Animal= (() => {
let count= 0;
class Animal {
constructor() {}
static increaseCount() {
count += 1;
}
static getCount() {
return count;
}
}
return Animal;
})();
console.log(Animal.getCount());
Animal.increaseCount();
console.log(Animal.getCount());