Coffeescript 为什么我们需要使用“除非和”&引用;一起而不是单独

Coffeescript 为什么我们需要使用“除非和”&引用;一起而不是单独,coffeescript,Coffeescript,在这种情况下,如果可以使用if like,那么需要同时使用“除非”和“?”吗 unless person.present? 相当于 if person.present 它们不是等价物 doSomeThing()除非有人在场? 仅当person.present为null doSomeThing()除非有人在场 如果person.present是false值,则将执行 doSomeThing()如果有人在场 如果person.present是true值,则将执行 检查。也有可能是因为问题中的打字

在这种情况下,如果可以使用if like,那么需要同时使用“除非”和“?”吗

unless person.present?
相当于

if person.present

它们不是等价物

doSomeThing()除非有人在场?
仅当
person.present
null

doSomeThing()除非有人在场
如果
person.present
false
值,则将执行

doSomeThing()如果有人在场
如果
person.present
true
值,则将执行


检查。

也有可能是因为问题中的打字错误。除非您在
person
上有一个“per sent”属性,否则它总是未定义的,这是错误的。

doSomeThing()除非person.present?仅当person.present为null或未定义时才会执行