2 ms·
mutability isn't really the problem here, even if 'this' is immutable the problem is that you closed over it with your event handler
by kevingadd 5y ago
mutability isn't really the problem here, even if 'this' is immutable the problem is that you closed over it with your event handler
- eyelidlessness 5y agoThe only closed reference to `this` in the example is a mutation, in an event handler. This is supposed retain the reference and it’s not even a leak. The simplest way to solve that would be to remove the event handler, but even simpler would be to treat `this` as a value type and never change it after construction. The other reference is easily rewritten as a WeakMap key and would not retain a reference, but easier still could be written as a local binding with no reference to `this` at all.