Underscore.js is a utility library which Backbone depends on. I’m afraid I don’t have a huge amount to say about it though because the only reason we’re using it is so that we can use Backbone. Lovely cuddly Backbone.
What is Underscore for?
It also supports some baisc HTML templating. This is the only feature I’ve actively used as it is valuable for producing Backbone Views. As a templater it’s pretty simple, which is probably a good thing. It’s been fit for all my extremely limited needs so far. This is tepid praise but based on inexperience rather than any negative feelings.
So why use Underscore?
So that we can use Backbone and because it makes life easier. A bit like functional jQuery.
Well that was short. Let’s talk about Lodash while we’re here. Lodash is a drop in replacement for Underscore. In theory this means that if you write your code base using Underscore, you can then change your mind and use Lo-Dash.
So Why Use Lo-Dash?
It’s a bit bigger but offers performance enhancements and some extra features. It’s also possible to generate specific subsections of Lo-Dash, so you can just get the bits relevant to Backbone and use that instead of the whole thing.
We haven’t decided between the two yet. Lodash sounds pretty good but the whole thing is 19kb compared to Underscore’s 4kb. Taking just a Backbone version will reduce that but right now I don’t know how much. These enhancements sound great but are they 15kb of download better?
The good news is since it drops in to replace, we should be able to build around underscore then swap in lodash to see if things are better.