_(gameState.loot)
.pick((value, key) -> key isnt "pickUpAnimations")
.filter ((d) -> _.isArray (d))
.reduce ((sum, d) -> sum.concat (d))
是给我这个错误:
TypeError: 'undefined' is not a function (evaluating '(function(d) {
鉴于此代码工作正常:
removedAnimations = _.pick(gameState.loot, (value, key) -> key isnt "pickUpAnimations")
removedAnimations = _.filter removedAnimations, ((d) -> _.isArray (d))
removedAnimations = _.reduce removedAnimations, ((sum, d) -> sum.concat (d))
removedAnimations
对我来说,似乎这些应该做同样的事情。的gameState.loot
架构是这样的:
loot: {
ttl: 6000
slowBlinkWhenTtlLessThanPercent: 60
fastBlinkWhenTtlLessThanPercent: 30
resurrections: []
gold: []
health: []
equipment: []
pickUpAnimations: []
}
顺便说一句,这是第一个例子中所产生的JavaScript:
return _(gameState.loot).pick(function(value, key) {
return key !== "pickUpAnimations";
}).filter((function(d) {
return _.isArray(d);
}).reduce((function(sum, d) {
return sum.concat(d);
})));
我试图@这个Blender的建议:
_(gameState.loot)
.pick (value, key) -> key isnt "pickUpAnimations"
.filter (d) -> _.isArray (d)
.reduce (sum, d) -> sum.concat (d)
但是,这给了我这个错误:
>> TypeError: 'undefined' is not a function (evaluating '"pickUpAnimations".filter(function(d) {
这里的JavaScript的样子:
return _(gameState.loot).pick(function(value, key) {
return key !== "pickUpAnimations".filter(function(d) {
return _.isArray(d.reduce(function(sum, d) {
return sum.concat(d);
}));
});
});
不知道是什么问题,但你可以删除一些括号https://gist.github.com/elclanrs/8838052 – elclanrs