8 ms·
Repeatedly used inline object literals: Object literals are one of the best features of Javascript, learn to love them. In the example cited, you already have
by jrajav 14y ago
Repeatedly used inline object literals:
Object literals are one of the best features of Javascript, learn to love them. In the example cited, you already have a function dedicated to creating this object; why would you need to further obfuscate it by delegating the actual leg work to a buzzword-filled framework (or worse, vanilla constructors)? Even for more complex examples, I find it clearer and simpler to use an extend() or clone() method than something that tries to emulate classes.
Strict equality everywhere:
You cherry-picked two simple examples, but normally it's more complex than that. Javascript has rather odd coercion, and it will bite you if you try to memorize all the cases where it's safe to use ==. It's not really that === is "strict", it's just that it generally works how == was supposed to. More importantly, though, there's never any harm in using === instead of ==, so why would you use the latter? Why is === "overkill?" Because it's one character more? I fail to see the argument for not using it, except to play the devil's advocate.
Strict coherence to a standard:
This is a fine swing to take if you're doing hobby work, in fact it's very healthy, but if you're working on any sort of larger project where you are or will be collaborating with others, it is nothing short of essential to agree on standards for everything from brace style to camel case to testing frameworks. Almost every other argument concerning style, practices, and idioms falls apart in favor of consistency.
- pretoriusB 14y agoRe: strict equality everywhere. If you "fail to see the argument for not using it", then you're not trying hard enough. Javascript was not designed with strict equality check in mind. The coercion it does can be harmful if you don't know how it works, but it can be very useful and liberating if you do. Essentially, but restricting yourself to "strict equality" you make Javascript a less dynamic language. Sometimes "20" is as good as 20. Dimitry Baranovsky, of Raphael fame, wrote about this specific issue: http://dmitry.baranovskiy.com/post/typeof-and-friends http://dmitry.baranovskiy.com/post/typeof-and-friends