I'm working with a nested function similar to the one below:
function counter() {
let count = 0;
function increment() {
count++;
}
return {
count: () => count,
increment: increment
};
}
const myCounter = counter();
myCounter.increment();
console.log(myCounter.count())
This appears to work fine but is there any way to return the updated count as just the value instead of a function? Ideally the goal is to be able to access the updated count with just myCounter.count instead of myCounter.count()
count: () => countis a function that returns by value.counter = {count: 0, increment: function(){return ++this.count;}}