Hacker News new | ask | show | jobs
by alongub 4227 days ago
It's not that JavaScript syntax is difficult. It's that there are some common patterns that repeat themselves so much times.

For example, safe object navigation. This code in Spider/CoffeeScript:

    var x = a?.b?.c?.d;
compiles to something like:

    var x = typeof a !== "undefined" && a && a.b && a.b.c ? a.b.c.d : void 0;
2 comments

You can also handle problems like this via libraries. For example, underscore-contrib [1] does it this way:

    var x = _.getPath(a, "b.c.d");
There are definitely advantages to having this pattern baked into the language, though.

[1] http://documentcloud.github.io/underscore-contrib/

I've been using node-jsx and jsx-loader to bring JS Harmony syntax into projects I'm working on now. The last great hurdle to make JS a language that's easy to express in is the existential operator. It sucks how often you have to manually null-check in JS.

I'm mighty tempted to write a Webpack plugin to make `?` usable in vanilla JS.