[英]Ramda undefined when using compose
我正在完成第五章的“最基本指南”練習。 我已經將Ramda與
var R = require('ramda');
並編寫了輔助函數:
var _average = function(xs) {
return R.reduce(R.add, 0, xs) / xs.length;
};
單獨使用就可以正常工作
_average(R.map(R.prop('dollar_value'), cars));
但是當我這樣寫的時候:
var averageDollarValue = R.compose(_average(), R.map(R.prop('dollar_value')));
我收到以下錯誤
Uncaught TypeError: Cannot read property 'reduce' of undefined
有人可以解釋為什么會這樣嗎?
合成中的括號表示您正在合成中調用函數_average。 嘗試刪除它們,這對我有用。 這是代碼片段。
var averageDollarValue = R.compose(_average, R.map(R.prop('dollar_value')));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.