最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using lodash instead of underscore in Backbone.js application - Stack Overflow

programmeradmin6浏览0评论

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
 |  Show 1 more ment

3 Answers 3

Reset to default 9

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 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).

发布评论

评论列表(0)

  1. 暂无评论