【发布时间】:2016-02-06 02:07:31
【问题描述】:
这甚至可能吗?继续阅读关于此的相互矛盾的报告。
我有一个 Marionette 应用,刚刚升级到 2.4.4。
如果我用 lodash 代替下划线 - 使用 requireJS,
map: {
'*': {
'underscore': 'lodash'
}
},
// 'underscore':'/resource/vendor/backbone.marionette/underscore',
'lodash':'/resource/vendor/lodash/lodash.min',
我收到以下错误...
Uncaught TypeError: Cannot read property 'vent' of undefined
lodash 加载正常,只是木偶在抱怨。
看来466 线上的上下文this 是未定义的
463 _proxyMethods: function() {
464 _.each([ "vent", "commands", "reqres" ], function(system) {
465 _.each(messageSystems[system], function(method) {
466 this[system][method] = proxyMethod(this, system, method);
467 }, this);
468 }, this);
469 }
有什么建议吗?
【问题讨论】:
-
嗯,很有趣。
messageSystems不是undefined,所以第 465 行(messageSystems[system])失败了? -
不,这很奇怪。使用调试器,它的 def
this是未定义的。它正在尝试解决...this["vent"]["on"] -
我认为这可能与嵌套的每个有关,两者都传入
this作为上下文 - 但我模拟了上面相同的函数,它工作正常 -
嗯,lodash 不再将
context作为.each中的第三个参数...` function forEach(collection, iteratee) { return baseEach(collection, toFunction(iteratee)); }` 所以上下文在上面丢失了 -
是的,就是这样,lodash 3.10.1 工作正常 - 它在新的 lodash 中缺少上下文,木偶不兼容
标签: javascript backbone.js underscore.js marionette lodash