-
Notifications
You must be signed in to change notification settings - Fork 6
Function Invocation
Related: Function Definition
Math.round(123.456)
Math.random() # functions with no params must be invoked this wayAny value, A, followed by a value, B, after it on the same line is treated as a function invocation: A(B).
Math.round 123.456Any value, A, can also be followed by a Value-List, to pass more than one parameter to the function invocation:
# explicit value list
Math.round 123.456, 0.1Lastly, commas are optional after atomic literals (strings, numbers, ...):
# implicit value list
Math.round 123.456 0.1Any value (a) followed by a block invokes (a) as a function. Each statement in the block is an argument to that function.
Math.round
123.456Full block-function-invocation have traditionally been hard to implement because of the ambiguities between invocation-blocks and control blocks.
# is this:
if foo
bar
# (a) this? (javascript)
if (foo(bar)) {}
# or (b) this? (javascript)
if (foo) {bar}To resolve this, CaffeineScript gives if, or any other similar control-block priority. The above example resolves to option (b).
Here are some more complex examples:
if foo
bar
baz
# == if (foo(bar)) {baz}
foo
bar
baz
# == foo(bar(baz))Tail-ifs followed by a block are no longer tail-ifs:
a if b
c
# == a(b ? c : undefined)And the ultimate example:
# Below not recommended :)
if a
b
c
d
e
# == if (a(b(c))(d)) {e}- Home
- Get Started
- Benefits
- Highlights
- Productivity by Design
- CaffeineScript Design
- What is CaffeineScript Good For?
- Get the most out of JavaScript
- Language Comparison
- CHANGELOG
- Blocks Instead of Brackets
- Binary Line-Starts
- Everything Returns a Value
- Streamlined Modules
- Scopes and Variables
- Optional Commas
- Semantics
- Ambiguities