Recently I noticed that there is not a difference between these two snippets.
function step() {
if (!this.counter) this.counter = 0;
return this.counter++;
}
console.log(step()); // -> 0
console.log(step()); // -> 1
console.log(step()); // -> 2
function step() {
if (!this.counter) this.counter = 0;
return this.counter++;
}
step.counter = 10;
console.log(step()); // -> 0
console.log(step()); // -> 1
console.log(step()); // -> 2
Why does setting a function property not affect it's this
?