Coffeescript 切换时
Coffescript switch when
我的咖啡脚本如下:
level = switch
when 0 <= value <= 1 then 0
when 1 < value <= 2 then 1
when 2 < value <= 3 then 2
when 3 < value <= 4 then 3
when 4 < value <= 5 then 4
else 6
为什么我得到:
Uncaught Error: ExecJS::ProgramError: [stdin]:15:4: error: unexpected
when when 1 < value <= 2 then 1
这很好用:
when value <= cool then 0
when value >= warm then 4
else
bucketSize = (warm - cool) / 3 # Total # of colours in middle
Math.ceil (value - cool) / bucketSize
这也有效:
level = switch
when value <= 1 then 0
when value <= 4 then 4
else 5
直到我添加
当值 <=2 然后 1
一切都是为了缩进。
level = switch
when 0 <= value < 1 then 0
when 1 <= value < 2 then 1
when 2 <= value < 3 then 2
when 3 <= value < 4 then 3
when 4 <= value <= 5 then 4
else 5
我把代码放在这里:http://www.coffeelint.org/
然后检查了缩进。
我的咖啡脚本如下:
level = switch
when 0 <= value <= 1 then 0
when 1 < value <= 2 then 1
when 2 < value <= 3 then 2
when 3 < value <= 4 then 3
when 4 < value <= 5 then 4
else 6
为什么我得到:
Uncaught Error: ExecJS::ProgramError: [stdin]:15:4: error: unexpected when when 1 < value <= 2 then 1
这很好用:
when value <= cool then 0
when value >= warm then 4
else
bucketSize = (warm - cool) / 3 # Total # of colours in middle
Math.ceil (value - cool) / bucketSize
这也有效:
level = switch
when value <= 1 then 0
when value <= 4 then 4
else 5
直到我添加 当值 <=2 然后 1
一切都是为了缩进。
level = switch
when 0 <= value < 1 then 0
when 1 <= value < 2 then 1
when 2 <= value < 3 then 2
when 3 <= value < 4 then 3
when 4 <= value <= 5 then 4
else 5
我把代码放在这里:http://www.coffeelint.org/
然后检查了缩进。