这不起作用的原因是
json
响应对象的方法不是纯函数。这真是一种方法。当你使用
pipe(prop('json'), call)
json文件
方法实际使用
this
. 拉姆达的
call
这
对象。
有一个拉姆达替代方案:
const toJSONRamda = R.invoker(0, 'json')
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(toJSONRamda)
.then(console.log)
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>
invoker
使用方法。这些应该有助于描述其工作原理:
R.invoker(0, 'method')(obj) = obj['method']()
R.invoker(1, 'method')(a, obj) = obj['method'](a)
R.invoker(2, 'method')(a, b, obj) = obj['method'](a, b)
//...
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(resp => resp.json())
.then(console.log)
如果这只是一个学习练习,那么,无论如何,请尝试把它变成一个无点的版本。但我会留下它,因为它是生产代码。