1

为什么当我在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)

我在想这是因为 RT 总是返回 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)
  })
)
4

1 回答 1

3

R.T评估true任何输入。因此R.ifElse(R.T, f, g)可以简化为f

在我看来,您正在寻找R.ifElse(R.identity, f, g),但这可能通过... ? ... : ....

于 2015-07-29T23:33:36.247 回答