Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using lodash instead of underscore in Backbone.js application

I'm writing a Backbone application and as I'm reading the documentation online, what I understand is that Backbone's only hard dependency is Underscore. However, I'd like to use Lodash instead of Underscore. Can someone provide steps as to how I can do this?

like image 293
wmock Avatar asked Mar 19 '15 07:03

wmock


People also ask

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.

Is lodash still needed?

But Sometimes You Do Need Lodash Not every Lodash utility is available in Vanilla JavaScript. You can't deep clone an object, for example. That's why these libraries are far from obsolete. But if you're loading the entire library just to use a couple of methods, that's not the best way to use the library.

Why we are using lodash?

Lodash is a popular javascript based library which provides 200+ functions to facilitate web development. It provides helper functions like map, filter, invoke as well as function binding, javascript templating, deep equality checks, creating indexes and so on.


2 Answers

If you are using Browserify, check out Browserify Swap or Aliasify

Personally I use Browserify Swap. Example package.json usage:

  "browserify": {
    "transform": [
      "browserify-swap"
    ]
  },
  "browserify-swap": {
    "@packages": [
      "underscore"
    ],
    "all": {
      "underscore.js$": "lodash"
    }
  }
like image 112
Michael Avatar answered Oct 31 '22 17:10

Michael


Up to version 2.4.1, lodash published a "Underscore compatible" version.

https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.underscore.js

You can use that as a drop-in replacement.

As of 3.0, they removed this build.

Removed the underscore build

https://github.com/lodash/lodash/wiki/Changelog

like image 35
Guilherme Rodrigues Avatar answered Oct 31 '22 17:10

Guilherme Rodrigues