Juv*_*uve 23 syntax shortcut try-catch coffeescript
我有时写代码如下:
try doSomething()
catch e
handleError e
Run Code Online (Sandbox Code Playgroud)
这不是什么好看和干净的coffeescript代码应该是什么样子.
有没有办法写:
try doSomething()
catch e handleError e #<-- will not compile
Run Code Online (Sandbox Code Playgroud)
这将在我的try/catch语句中节省大约33%的代码行;)
Juv*_*uve 44
编写try/catch单行程序就像if-then one-liners或使用then关键字循环单行:
try doSomething()
catch e then handleError e
finally cleanUp()
Run Code Online (Sandbox Code Playgroud)
如果您愿意,甚至可以将它放在一行:
try doSomething() catch e then handleError e finally cleanUp()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16622 次 |
| 最近记录: |