Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use the Underscore-compatible build of Lo-Dash when using it with BackboneJS?

Tags:

I noticed that Lo-Dash has a special Underscore-compatible build, ostensibly to address differences in function arguments/operations (since Lo-Dash is a superset of Underscore, I assume there are no Underscore functions missing from Lo-Dash).

I've also noticed that BackboneJS can be used with either Underscore or Lo-Dash.

My question: would it be unwise to use a "normal" build of Lo-Dash with BackboneJS? I can't find any indication of whether or not people are doing this in the wild, but it seems like a bad idea, especially if BackboneJS relies on functions that may be different in these builds. At the same time, it would be nice to use some of the newer functions in Lo-Dash, so I'd hate to miss out on those if it isn't necessary.

like image 726
Matt Diamond Avatar asked Jun 20 '13 21:06

Matt Diamond


People also ask

What is Backbone used for?

It is designed for developing single-page web applications, and for keeping various parts of web applications (e.g. multiple clients and the server) synchronized. Backbone was created by Jeremy Ashkenas, who is also known for CoffeeScript and Underscore. js.

Is Lodash compatible with underscore?

Because Lodash is updated more frequently than Underscore. js, a lodash underscore build is provided to ensure compatibility with the latest stable version of Underscore.

What is Backbone framework?

Backbone. js is a model view controller (MVC) Web application framework that provides structure to JavaScript-heavy applications. This is done by supplying models with custom events and key-value binding, views using declarative event handling and collections with a rich application programming interface (API).


2 Answers

I usually recommend trying Lo-Dash as is first. If you have issues you can drop back to the Underscore compat build. This goes for new projects or those already using Underscore and wanting to change.

You can also leverage the build utility and say create a version of Lo-Dash that uses the Underscore chaining style with something like lodash -d plus=chain.

like image 23
John-David Dalton Avatar answered Sep 22 '22 05:09

John-David Dalton


[edit] From personal experience after using lodash for quite a while, I find that the differences are not too big a deal. I would suggest you DO use the normal build, but if you don't want to take any risk, go with the compat build.


To know the answer, see this wiki page, which summarizes the differences between the underscore Lo-Dash build and plain Lo-Dash:

https://github.com/lodash/lodash/wiki/build-differences

Underscore build (includes the Backbone build which is a subset of the Underscore build)

  • Lo-Dash’s intuitive chaining is replaced with Underscore’s explicit chaining style The _.chain method is still there if you want to use it.
  • The _.each method does not exit early if the callback returns false
  • The _.defaults and _.extend method iterate over inherited properties of source objects
  • Extra features are removed from methods like _.contains, _.omit, _.pick, and _.template
like image 175
kumarharsh Avatar answered Sep 18 '22 05:09

kumarharsh