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?
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?
Share Improve this question asked Mar 19, 2015 at 7:21 wmockwmock 5,4924 gold badges43 silver badges62 bronze badges 6- backbone depends a lot on underscore to get it job done. you might need to write plete library again in case you dont want to use underscore – StateLess Commented Mar 19, 2015 at 7:26
- 1 1. Include lodash.js instead of underscore.js, 2. Done – ivarni Commented Mar 19, 2015 at 12:02
- 1 replace underscore with lodash and fix possible errors) just wondering what are you going to reach by this replace? – Evgeniy Commented Mar 19, 2015 at 12:29
- 3 @Evgeniy lodash has some features that underscore lack, if OP wants to use those features it makes more sense to replace underscore than to add both. – ivarni Commented Mar 19, 2015 at 15:31
- 1 As I remember, in our project we've just replaced an import of underscore with lodash and that's all. @Evgeniy, see: stackoverflow./a/13898916/1203773 – Eugene Naydenov Commented Mar 19, 2015 at 15:57
3 Answers
Reset to default 9If 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 patible" version.
https://cdnjs.cloudflare./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./lodash/lodash/wiki/Changelog
You could also check out Exoskeleton - it's a drop-in replacement for Backbone that doesn't have Underscore as a requirement so you can simply remove it (and use lodash instead of it).