使用除非和“?”有什么需要?在这种情况下,您可以一起使用 if like
unless person.present?
相当于
if person.present
最佳答案
它们不是等价的。doSomeThing() unless person.present?
仅当 person.present
时才执行是 null
doSomeThing() unless person.present
如果 person.present
将执行是 false
值(value)doSomeThing() if person.present
如果 person.present
将执行是 true
值(value)
检查 compiled javascript .
关于coffeescript - 为什么我们需要同时使用unless和 "?"而不是单独使用if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16088437/