为什么当我在这里运行 ifElse
方法时 false
会记录“函数二 (onTruthy)”?
var x = R.ifElse(R.T, function(){
console.log("function two (onTruthy)")
// console.log(arguments)
}, function(){
console.log("function three (onFalsy)")
// console.log(arguments)
})
x(false)
我认为这是因为 R.T 总是返回 true。也许使用 _.isMatch我配得上吗?
更新:刚试过:
var x = R.pipe(
R.partialRight(R.match, true),
R.partialRight(R.ifElse, function(){
console.log("function two (onTruthy)")
// console.log(arguments)
}, function(){
console.log("function three (onFalsy)")
// console.log(arguments)
})
)
最佳答案
R.T
对任何输入计算 true
。因此R.ifElse(R.T, f, g)
可以简化为f
。
在我看来,您正在寻找 R.ifElse(R.identity, f, g)
,但这或许可以通过 ... 更好地表达? ... : ...
。
关于javascript - Ramda ifElse 行为异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31711664/