Below is some code demostrates static local variable in C/C++. Counter would be added for each time when btnTestOnclick is called -- counter can be accumulated.
void btnTestOnclick()
{
static int counter = 0;
counter++;
}
But in the below JS code,
function btnTestOnclick() {
class temp{
static counter=0;
};
console.log(temp.counter);
temp.counter+=1;
}
This temp.counter can't be accumulated, every time it's 0. I know moving the temp class out of the function would work, but this class is supposed to logically be local since only btnTestOnclick would use it.
How do you think about it?