3 ms·
facepalm > The mechanisms to retain memory have a lot in common. Classes use this, which refers to the object’s instance, while functions implement closures -
by koprulusector 5y ago
facepalm
> The mechanisms to retain memory have a lot in common. Classes use this, which refers to the object’s instance, while functions implement closures - the ability to remember all the variables within their scope.
Non-arrow functions, like the example, defined with the `function` keyword also have `this` context. If you want to limit `this` and rely solely on closures, you probably want an arrow function.