Context and variable scope in ES6 loops and forEach
问题 In ES5, if I have to refer to the this context of parent function in child function I have to store it in a variable and access it inside child function using that variable. Something like this ... // variant 1 var self = this; this.nums.forEach(function (v) { if (v % 5 === 0) self.fives.push(v); }); ECMAScript has arrow functions so I can avoid this: // variant 2 this.nums.forEach((v) => { if (v % 5 === 0) this.fives.push(v) }) The question that I have is: If I was to declare a variable temp