2010-01-26 10:52:05 -05:00
|
|
|
func: (first, second, rest...) ->
|
2010-01-24 23:40:45 -05:00
|
|
|
rest.join ' '
|
2009-12-31 17:50:12 -05:00
|
|
|
|
2010-01-24 23:40:45 -05:00
|
|
|
result: func 1, 2, 3, 4, 5
|
2009-12-31 17:50:12 -05:00
|
|
|
|
2010-02-16 19:45:25 -05:00
|
|
|
ok result is "3 4 5"
|
2009-12-31 19:52:13 -05:00
|
|
|
|
|
|
|
|
2010-06-12 19:05:13 -04:00
|
|
|
gold: silver: bronze: theField: last: null
|
2009-12-31 19:52:13 -05:00
|
|
|
|
2010-03-17 14:41:09 -04:00
|
|
|
medalists: (first, second, third, rest..., unlucky) ->
|
2009-12-31 19:52:13 -05:00
|
|
|
gold: first
|
|
|
|
silver: second
|
|
|
|
bronze: third
|
2010-06-12 19:05:13 -04:00
|
|
|
theField: rest.concat([last])
|
2010-03-17 14:41:09 -04:00
|
|
|
last: unlucky
|
2009-12-31 19:52:13 -05:00
|
|
|
|
|
|
|
contenders: [
|
|
|
|
"Michael Phelps"
|
|
|
|
"Liu Xiang"
|
|
|
|
"Yao Ming"
|
|
|
|
"Allyson Felix"
|
|
|
|
"Shawn Johnson"
|
|
|
|
"Roman Sebrle"
|
|
|
|
"Guo Jingjing"
|
|
|
|
"Tyson Gay"
|
|
|
|
"Asafa Powell"
|
|
|
|
"Usain Bolt"
|
|
|
|
]
|
|
|
|
|
2010-01-24 23:40:45 -05:00
|
|
|
medalists "Mighty Mouse", contenders...
|
2009-12-31 19:52:13 -05:00
|
|
|
|
2010-02-16 19:45:25 -05:00
|
|
|
ok gold is "Mighty Mouse"
|
|
|
|
ok silver is "Michael Phelps"
|
|
|
|
ok bronze is "Liu Xiang"
|
2010-03-17 14:41:09 -04:00
|
|
|
ok last is "Usain Bolt"
|
2010-06-12 19:05:13 -04:00
|
|
|
ok theField.length is 8
|
2010-02-20 18:25:36 -05:00
|
|
|
|
2010-03-17 12:25:04 -04:00
|
|
|
contenders.reverse()
|
|
|
|
medalists contenders[0...2]..., "Mighty Mouse", contenders[2...contenders.length]...
|
|
|
|
|
|
|
|
ok gold is "Usain Bolt"
|
|
|
|
ok silver is "Asafa Powell"
|
|
|
|
ok bronze is "Mighty Mouse"
|
2010-03-17 14:41:09 -04:00
|
|
|
ok last is "Michael Phelps"
|
2010-06-12 19:05:13 -04:00
|
|
|
ok theField.length is 8
|
2010-02-20 18:25:36 -05:00
|
|
|
|
2010-04-03 10:39:32 -04:00
|
|
|
medalists contenders..., 'Tim', 'Moe', 'Jim'
|
2010-03-17 22:07:11 -04:00
|
|
|
ok last is 'Jim'
|
|
|
|
|
|
|
|
|
2010-02-20 18:25:36 -05:00
|
|
|
obj: {
|
2010-04-03 10:39:32 -04:00
|
|
|
name: 'moe'
|
2010-02-20 18:25:36 -05:00
|
|
|
accessor: (args...) ->
|
|
|
|
[@name].concat(args).join(' ')
|
|
|
|
getNames: ->
|
|
|
|
args: ['jane', 'ted']
|
|
|
|
@accessor(args...)
|
|
|
|
}
|
|
|
|
|
2010-04-03 10:39:32 -04:00
|
|
|
ok obj.getNames() is 'moe jane ted'
|
2010-03-18 09:27:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
crowd: [
|
|
|
|
contenders...
|
|
|
|
"Mighty Mouse"
|
|
|
|
]
|
|
|
|
|
|
|
|
bests: [
|
|
|
|
"Mighty Mouse"
|
|
|
|
contenders[0..3]...
|
|
|
|
]
|
|
|
|
|
|
|
|
ok crowd[0] is contenders[0]
|
|
|
|
ok crowd[10] is "Mighty Mouse"
|
|
|
|
|
|
|
|
ok bests[1] is contenders[0]
|
2010-04-24 15:57:15 -04:00
|
|
|
ok bests[4] is contenders[3]
|
|
|
|
|
|
|
|
|
|
|
|
# Finally, splats with super() within classes.
|
|
|
|
|
|
|
|
class Parent
|
|
|
|
meth: (args...) ->
|
|
|
|
args
|
|
|
|
|
|
|
|
class Child extends Parent
|
|
|
|
meth: ->
|
|
|
|
nums: [3, 2, 1]
|
|
|
|
super nums...
|
|
|
|
|
2010-06-29 21:03:50 -04:00
|
|
|
ok (new Child).meth().join(' ') is '3 2 1'
|
2010-05-08 12:44:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Functions with splats being called with too few arguments.
|
|
|
|
pen: null
|
|
|
|
method: (first, variable..., penultimate, ultimate) ->
|
|
|
|
pen: penultimate
|
|
|
|
|
|
|
|
method 1, 2, 3, 4, 5, 6, 7, 8, 9
|
|
|
|
ok pen is 8
|
|
|
|
|
|
|
|
method 1, 2, 3
|
|
|
|
ok pen is 2
|
|
|
|
|
|
|
|
method 1, 2
|
|
|
|
ok pen is 2
|
2010-07-13 22:16:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Array splat expansions with assigns.
|
|
|
|
nums: [1, 2, 3]
|
|
|
|
list: [a: 0, nums..., b: 4]
|
|
|
|
ok a is 0
|
|
|
|
ok b is 4
|
|
|
|
ok list.join(' ') is '0 1 2 3 4'
|