Echo JS 0.11.0

<~>
pyrokinetiq@gmail.com 2545 days ago. link 2 points
It may make things appear more concise and even simpler in the short term, but over a long term it impairs readability of your code. It also increases the cognitive load, in bigger `with` block you would need to constantly keep in mind what object is being used, without it you explicitly reference the object so it's clear.

It can also lead to confusing commits e.g. if you change the body of a `with` expression to access new child properties of the object you pass, it won't be very clear in the commit where those values are coming from because the `with` statement will likely not be visible in the diff.

If you don't want to explicitly refer to a long named variable or a long property chain, I would recommend assigning it to a concisely named variable rather than using `with`

Replies

harry.nguyen@adslot.com 2543 days ago. link 1 point
doesn't convince me, same argument can be made about function params and named import, and destructuring (and renamed destructuring), in the first 2 cases the call sites are even far away from the declaration, unlike "with" which is very scoped.

kotlin has "with" and people seem to be ok with it. In fact "with" is the closest thing javascript has that might make  kotlin's dsl style builder possible. Of course, the reality we have is jsx.

I'd say the only real reason is that at some point in the past people decided that it should be forbidden in strict mode and now it's literally impossible to use without messing around with your linter/transpiler.