[ /js/latest ]

After hesitating for a while, I've started to use some of Javascript's newer features, available in ECMAScript 6. While there are a few features that have thrown me off, there are a few things I've begun to appreciate.

I tend to prefer functional programming over an object-oriented style, though in Javascript you almost always have to use a little bit of object orientation to get things done. I don't find it a big deal that 'map' and 'filter' are array methods, and not functions. Likewise, length is an object attribute and not a function.

The thing about object orientation that a lot of people have trouble with is inheritance, and the lexical this. ES6 Arrow functions do away with the lexical this, but they don't expose lexical arguments either. I know of people who have been tripped up by this, but they're documented in the spec, if you bother to read it, as I did when I heard about people getting tripped up).

There are a bunch of things that are a bit screwy, I really don't like that Javascript now has classes now, but I can't really do much about it. I hope to be able to stay away from code that uses the features I don't like (if I have to hack on it), but there are a few features that I find really helpful.

const

The const keyword is one such feature that I've found useful. It's a fairly trivial feature, but being able to declare that some value is not to be mutated has helped me track down bugs faster. If I try to reassign a const, I get an error. Otherwise, it's business as normal, no harm done.

Using these features

I'll probably write more about the features I'm using (and how I'm using them) in a dedicated article, but that's all irrelevant if I don't have a version of nodejs that lets me use these features (unless you're using them in a browser that supports them).

Luckily, there's this page which explains how to install the latest version on operating systems which tend to fall behind.

On Debian (which tends to fall waaaaay behind everyone else):

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

...and you should end up with an ES6 setup by default.

Conclusion

This doesn't mean that you have to use the latest features in your code, and I do recommend writing code that's backwards compatible, since it will make it much easier for people who haven't updated yet (or those who for some reason are unable to update). You will, however, benefit from improvements to the platform, such as binding to all network interfaces via a .listen('::') directive. This was the feature that finally prompted me to update on my servers, since I tend to want to expose an HTTPD on both IPv4 and IPv6.

--ansuz

2016-04-02