Is it me, or did the author tack on a new topic regarding the use of && and ||? The fact that they return the controlling operand is quite useful. Consider a situation where you want to check the property of an object, but don't know if that object is null: var foo = obj && obj.bar; I find this much more readable than: var foo = null; if (obj) { foo = obj.bar; } You can accomplish the same thing with a ternary operat…
Brendan Eich: The infernal semicolon
141–143 of 143 posts
Re: Brendan Eich: The infernal semicolon
#142Earlier quoted context omitted.
I’m sorry, but I don’t know what “FIY” means, what your point is, or how your comment is a reply to mine. Consider re-phrasing?
I misspelled FYI - "for your information". You said there are only downsides, and no advantages; I just told you what the claimed advantage is for "abusing" ASI. I hope you're not just being snarky.
Re: Brendan Eich: The infernal semicolon
#143Earlier quoted context omitted.
I can't speak for Brendan, but I generally think && / || are great for assignment , but otherwise it's code-smell. var foo = obj && obj.bar; // great !isActive && $parent.toggleClass('open'); // smelly if (!isActive) $parent.toggleClass('open'); // better
if (!isActive) { $parent.toggleClass('open'); } // best Damian Conway of Perl fame wrote an excellent style guide for C in the early/mid 90s which I'm pretty sure explained why (I can't find my copy): Programmer A: if (!isActive) $parent.toggleClass('open'); Programmer B: if (!isActive) $parent.toggleClass('open'); doSomethingElse(); Oh dear.
// okay
if (!isActive) $parent.toggleClass('open');
// not okay
if (!isActive)
$parent.toggleClass('open');
That way you know when you change it to two lines, you have to add curlies.