Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用if进行意外的Coffeescript转换?_Coffeescript_Conditional Operator - Fatal编程技术网

使用if进行意外的Coffeescript转换?

使用if进行意外的Coffeescript转换?,coffeescript,conditional-operator,Coffeescript,Conditional Operator,这个咖啡脚本: x = y > z ? 'a' : 'b' : 我认为这是意料之中的,只是不直观 这在coffeescript中有更好的方法吗?如果而不是,您可以使用:: x = if y > z then 'a' else 'b' 这个 我想这就是我想要的,但我不知道我是否满意 咖啡脚本: x = if y > z then 'a' else 'b' Javascript x = y > z ? 'a' : 'b'; CoffeeScript的?运算符是存在运算

这个咖啡脚本:

x = y > z ? 'a' : 'b'
:

我认为这是意料之中的,只是不直观


这在coffeescript中有更好的方法吗?

如果
而不是
,您可以使用

x = if y > z then 'a' else 'b'
这个


我想这就是我想要的,但我不知道我是否满意

咖啡脚本:

x = if y > z then 'a' else 'b'
Javascript

x = y > z ? 'a' : 'b';

CoffeeScript的
运算符是存在运算符(“也使用浸泡”或“猫王”名称)。 例如:
context=window?全局

CoffeeScript的实现方法是
x=if x>z,然后'a'或者'b'
(或者
x=x>z和'a'或者'b'
,但是“and”操作数必须是真实的,才能工作),这将编译成您期望的三元运算符

x = if y > z then 'a' else 'b'
x = y > z ? 'a' : 'b';