从 Underscore 切换到 Lodash

Switching to Lodash from Underscore

我刚刚开始支持一个巨大的 Backbone 和 Marionette 应用程序。目前使用Underscore,版本为1.7.0。

我想切换到 Lodash 最新版本以利用新功能,例如我今天从其他 post、_.has() 的深度搜索中学到的功能.我也在使用 RequireJS

切换到 Lodash 最安全的方法是什么?我

1. bower install lodash
2. update require.confg

    "underscore": "../components/underscore/underscore",
    "underscore.string": "../components/underscore.string/lib/underscore.string",

    and update the values to point to `lodash` paths but keep the property names?

这是一个可能适用于也可能不适用于 Lodash 的示例。这只是一个例子。

convertModels: function convertModels() {
  _.each(this.models, _.bind(function (model) {
    model = this.convertItem(model);
  }, this));
},

这个 post 也是关于 "will I need to change some of the Underscore codes" 或者 Lodash 是否能够处理并产生相同的输出。或者我只需要检查应用程序,看看会发生什么?

前段时间遇到了同样的任务,通过 require config 做到了这一点:

require.config({
    paths: {
        // ..
        "lodash": "libs/lodash-3.9.3",
        "backbone": "libs/backbone-1.2.0",
        // ..
    },
    map: {
        "*": {
            // use lodash instead of underscore
            "underscore": "lodash"
        }
    }
}

..详情在这里:http://requirejs.org/docs/api.html#config-map 我经常使用 _ 函数,切换后无需更改任何内容。