简体   繁体   English

如何在coffeescript中“if undefined”?

[英]How to do “if undefined” in coffeescript?

How would I get this in CoffeeScript? 我如何在CoffeeScript中获得这个? This is the JS that I am trying to get : 这是我想要的JS:

if (value === undefined) {
  return model.get('isCompleted');
} 

Basically, When I am trying this : 基本上,当我尝试这个时:

if value is undefined
  model.get 'isCompleted'

I am getting this in the JS : 我在JS中得到这个:

if (value === void 0) {
  model.get('isCompleted');
}

Is there no way to display "undefined" without : 没有:没有办法显示“未定义”:

if value is `undefined`

I somehow don't want to use ``. 我不知何故不想用``。

In case you're not aware of the CoffeeScript existential operator , that makes it real easy to check whether a variable is defined (ie it's not undefined or null ). 如果您不了解CoffeeScript 存在运算符 ,则可以很容易地检查变量是否已定义(即它undefined或为null )。 If it doesn't matter to you whether value is null or undefined, I'd use that. 如果对你来说无关紧要是值是null还是未定义,我会使用它。 Use it like so: 像这样使用它:

if !value?
  model.get 'isCompleted'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM