3 ms·
> This is specifically about calling a non-member that is already in scope, as if it were a member. I understand what you wrote. `with` is reserved, but disus
by carussell 9y ago
> This is specifically about calling a non-member that is already in scope, as if it were a member.
I understand what you wrote. `with` is reserved, but disused, however. And it wouldn't be the first reserved word that has different behavior based on the actual construct it appears in. Loops and switch statements both use `break`, for example. The language does this because the semantics are similar enough, and there's no point in polluting the list of reserved words when pulling double-duty with the one would do.
- spion 9y agoIn the case of 'break', it breaks out of the block of the current construct (loop, switch). with brings an object in scope, or calls something already in scope with the object as a this argument - the semantics will be exactly opposite in this case. Then it breaks chaining syntax (one nice thing we get), since everything will have to nest again: x::fn()::otherFn() vs (otherFn() with (fn() with x)) It brings more problems with ASI: fn() with (x); // is this fn() with (x), or fn(); with (x); do nothing