mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 19:11:22 -05:00
Merging in Tesco and rofrankel's soaks for function calls. A soaked check that fails will return undefined.
This commit is contained in:
@@ -109,3 +109,20 @@ ok x is - 1
|
||||
# Things that compile to ternaries should force parentheses, like operators do.
|
||||
duration = if options?.animated then 150 else 0
|
||||
ok duration is 0
|
||||
|
||||
|
||||
# function soak
|
||||
plus1 = (x) -> x + 1
|
||||
|
||||
ok plus1?(41) is 42
|
||||
ok (plus1? 41) is 42
|
||||
ok plus2?(41) is undefined
|
||||
ok (plus2? 41) is undefined
|
||||
|
||||
maybe_close = (f, arg) -> if typeof f is 'function' then () -> f(arg) else -1
|
||||
|
||||
ok maybe_close(plus1, 41)?() is 42
|
||||
ok (maybe_close plus1, 41)?() is 42
|
||||
ok (maybe_close 'string', 41)?() is undefined
|
||||
|
||||
ok 2?(3) is undefined
|
||||
|
||||
Reference in New Issue
Block a user