Re:Pythonic syntax to declutter Javascript
by nir on Thursday January 14, 2010 @09:58PM
(#1054134)
Javascript example in the article:
Can be made much cleaner:
I don't know about a whitespace-sensitive language in the browser. Much JS is written by non-coders, later quickly edited on live servers (yeah, I know. But that's reality) etc.. It all comes down to taste, of course, but personally I find Ruby at least as readable as Python, so I'm not sure whitespaces are where the elegance is found.
[ Parent
| on HN ]
With JavaScript 1.8.1:
function triangle(a,b)
a <= 0 || b <= 0 ? 0 : (a = a*a + b*b) > 0 ? Math.pow(a,.5) : 0;
Re:Pythonic syntax to declutter Javascript
by jrockway on Thursday January 14, 2010 @10:57PM
(#1054210)
Is ?: really not right-associative in JavaScript? I thought PHP was the only language that messed that one up...
I wrapped it with parentheses out of habit. updated
Re:Pythonic syntax to declutter Javascript
by jrockway on Thursday January 14, 2010 @11:04PM
(#1054219)
That's a relief :)
Re:Pythonic syntax to declutter Javascript
by WalkingDead on Friday January 15, 2010 @04:06AM
(#1054540)
Doesn't work on V8, at least not on the version I am using. Which JS engine is 1.8.1 complaint?