3 ms·
I'll admit to not being fully ready for all of JavaScript's footguns when I first switched from other languages, and most of the function related ones can be (a
by hansvm 6y ago
I'll admit to not being fully ready for all of JavaScript's footguns when I first switched from other languages, and most of the function related ones can be (as this article points out) mitigated by blindly wrapping everything in lambdas.
As one fun example suppose you're working with the snippet:
const f = foo.predicate; return arr.filter(f);
If foo is a class instance and references any instance variables via `this`, then just storing the method before you attempt to use it will cause the whole house of cards to blow up. So...adding a reference to `this` is a breaking change for even moderately sane code. That problem is also easily mitigated with lambdas: const foo = (x) => foo.predicate(x);