_(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