-
Notifications
You must be signed in to change notification settings - Fork 6
Array Literals
Shane Brinkman-Davis edited this page Mar 12, 2017
·
1 revision
CaffeineScript makes structured literals lightweight and fun! Examples:
# Array of 3-element Arrays
a =
"Bob" 1976 :male
"Alice" 1978 :female
# Array of 3 objects
b =
foo: 1
foo: 2
foo: 3# JavaScript-style - 19 tokens
a = [
["Bob", 1976, "male"],
["Alice", 1978, "female"]
]
# matchless: blocks and one-liners
a = []
[] "Bob", 1976, :male
[] "Alice", 1978, :female
# implicit arrays
a =
"Bob", 1976, :male
"Alice", 1978, :female
# implicit commas - 8 tokens
a =
"Bob" 1976 :male
"Alice" 1978 :female# array one-liners
a = [1, 2, 3]
a = [] 1, 2, 3 # one-liner array without bracket-matching
a = 1, 2, 3 # array is implicit when there are 2 or more elements
a = 1 2 3 # implicit commas after number and string literals
# array block
a = []
1
2
3
# implicit array block
a =
1
2
3- 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