Echo JS 0.11.0

<~>

cprecioso 1382 days ago. link 1 point
These are almost all horrible “tricks”, repealed for a long time. 

1. The function constructor is basically an eval, with almost the same problems. Running user input as code is a bad idea, and if it doesn’t need user input then just write the function as normal. 

2. “With” is slow and can cause plenty of ambiguity. It’s disallowed in strict mode. 

3. Like... sure? If you wanted to? Much better to indeed use parseInt and parseFloat (makes the conversion explicit and doesn't get confused with either string concatenation or number addition), and always give the radix parameter. Fun fact, old JS engines will interpret +"010" as 8.

4. Again... sure. It's good for descriptors and additional function data. BUT, if you're gonna have global state like that, you better make it explicit as a class with instance or static properties; or as an explicit argument.

5. Will throw in strict mode. Also... why? Different behaviors depending on the caller are bad etiquette and difficult to reason about (as well as needing to keep track of the possible callers). If you really need different behaviours, make different functions. Nobody is charging you for those.

6. Yes, we do. But as the article says, the only reason to ever use it is because JS etiquette in pre-strict mode times was horrible. In strict mode there's no real use for it. Moreover, void is an operator, not a function, so it will work like "void 0", it doesn't need parentheses.

Look, it's fun for a "JS archeology" or "hidden corners" thing, but it should have a big disclaimer on top that these are insecure, obsolete, slow, and just plain bad ideas. That's why we don't talk about them anymore. Right now it's just presented as "advanced tips for JS". A bit more digging into why these things are not done anymore and an explanation would have been a really good addition for this post.