Echo JS 0.11.0

<~>

amitport 2577 days ago. link 5 points
(pros/cons)
(-) requires training - this syntax may be unfamiliar/confusing to some people
(-) over-use is very bad - the problems are mentioned in MDN.
(+) when used exactly right - it saves a few characters

IMO, when working in a company/team/open-source-project it's just not worth the effort and risk (of over-use).


You can do something like this instead (a little more verbose but more readable for humans and compilers):
```
{
  const {loadEventEnd, navigationStart} = window.performance.timing;
  console.log(loadEventEnd - navigationStart);
}
```
kirilloid 2577 days ago. link 0 point
Whilst I in general agree, when writing into an object, you cannot emulate that easily. But that’s also unpredictable.
One slight typo and you are writing into wrong place. It’s just dangerous in these cases.
MaxArt 2577 days ago. link 3 points
The only real advantage in using `with` is that it works great with template compilation - i.e., a quite restricted case that could be worked around.

For the rest, we have better tools now. Array/object destructuring, spread operators and such make the code much clearer... and easier to write too.
pyrokinetiq@gmail.com 2576 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`
harry.nguyen@adslot.com 2574 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.
peterc 2576 days ago. link 1 point
It was heavily railed against in JavaScript: The Good Parts which had a huge effect I suspect.