I want to create a class that includes the following properties:
List
Count of List
so I thought I could do:
class MyList {
constructor() {
this._list = [];
this._listCount = this._list.length;
}
}
With the method I defined inside, I want to be able to push items into the list and I thought it would automatically increase the _listCount but it stays static. So even though the length of the _list property is 2, the _listCount stays at 0.
Here's the method I created inside my MyList class:
add(todo) {
this._list.push(todo);
}
Can someone explain to me why it doesn't automatically increase _listCount when I call the Method on the newly created instance?