Re:Show HN: Ferrum.js – Rust features in JS: traits and adva...
by Leszek on Wednesday July 03, 2019 @07:52AM
(#20343429)
You want a conditional expression in JavaScript ? you could use the ternary operator : you don't have to use it if you don't want to though;
[ Parent
| on HN ]
Re:Show HN: Ferrum.js – Rust features in JS: traits and adva...
by nicoburns on Wednesday July 03, 2019 @09:08AM
(#20343956)
Ternary operator don't nest very nicely though (they do nest , but it's not very readable). IMO a bigger difference is Rust's match and blocks also being expressions. These have no alternatives in JavaScript.
Re:Show HN: Ferrum.js – Rust features in JS: traits and adva...
by bfrydl on Wednesday July 03, 2019 @09:25AM
(#20344061)
Nesting multiple branches of ternary operators doesn't work well but if it's a sort of “if elseif elseif else” situation I think this looks pretty nice:
x > 0 ? 'positive' :
x < 0 ? 'negative' :
'zero'
Re:Show HN: Ferrum.js – Rust features in JS: traits and adva...
by nicoburns on Wednesday July 03, 2019 @09:32AM
(#20344110)
But not nearly as nice as:
match x {
0 => 'zero',
x if x > 0 => 'positive',
x if x < 0 => 'negative',
}
Re:Show HN: Ferrum.js – Rust features in JS: traits and adva...
by svrtknst on Wednesday July 03, 2019 @10:42AM
(#20344674)
I actually made a library for that!
It's published on npm and everything. It's small, a bit unpolished, maybe needs more docs, but it works pretty damn well if you ask me!
Re:Show HN: Ferrum.js – Rust features in JS: traits and adva...
by matthewhartmans on Wednesday July 03, 2019 @08:04AM
(#20343511)
I see what you did there ( ͡° ͜ʖ ͡°)