News for hackers. Stuff that matters.
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!

https://gitlab.com/svartkonst/match