Jul 7

Coding Javascript, the human way (with Underscore.js)

Being a Ruby and Python developer I am familiar with map, each, filter, collect, reduce, list comprehensions. This is what drove me from Java to the world of dynamic languages and ever since I have never looked back, actually I am thinking of taking up Clojure.

Yes, functional programming makes sense, it helps you build better and faster. We could say that Javascript belong to the Ruby/Python family. It’s dynamic and has some functional characteristics as Python and Ruby have. Some of the things you are used to in Ruby or Python may apply to Javascript other things not. Of course there are the new versions of ECMAScript that introduce map, reduce and other nice things, but… try to run them in the browser and I mean all popular browsers. Well good luck with that.

As we move more logic into the browser we need better building blocks to enable to write better and faster. CoffeScript is definetely a solution but occasionally you will need to read or edit another library or legacy code, so you have two languages in the browser! Fucking hell! There is a library that brings fresh air into Javascript, it’s named Underscore.js.

Underscore.js will bring lots of functions that are missing. It will not extend any Javascript object so that you can never think that a function was there. It creates its own namespace under the symbol _. After adding Underscore.js to my apps it became a default along with jQuery. I really cannot imagine how life was before it. Some fine examples (especially if you love one-liners as much as I do):

—-

—-

If you have not tried Underscore.js give it a try! If you hate Javascript you can love it, if you already love it… you still need it!

- Panos