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?
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.
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.
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.
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"
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With