-
Notifications
You must be signed in to change notification settings - Fork 48
side by side comparison
satyr edited this page Aug 14, 2011
·
54 revisions
CoffeeScript | Coco |
---|---|
square = (x) -> x * x `function cube(x){ return x * square(x) }` |
square = -> it * it function cube x x * square x |
$('.account').slice(1, -1) .addClass('active') .show 'slow' |
$ .account .slice 1, -1 .addClass \active .show \slow |
pythagorases = [] for a in [9..1] for b in [a...99] h = Math.sqrt aa + bb pythagorases.push [a, b, h] unless h % 1 |
pythagorases = for a from 9 to 1 by -1 for b from a til 99 h = Math.sqrt aa + bb [a, b, h] unless h % 1 |
mixin = (objects...) -> for obj in objects @[key] = val for own key, val of obj |
mixin = (...objects) -> import obj for obj of objects |
for filename, index in ['head', 'body', 'tail'] do (filename, index) => fs.readFile filename, (err, contents) => @compile filename, index, contents.toString() |
for filename, index of <[ head body tail ]> let err, contents <~ fs.readFile filename @compile filename, index, contents.toString() |
loop node = node.parentNode break unless node instanceof Element or node instanceof Elephant |
do node.=parentNode while node instanceof [Element, Elephant] |
alert( try nonexistent / undefined catch error "And the error is ... " + error ) |
alert do try nonexistent / void catch "And the error is ... " + e |
exports.Cat = class Cat extends Animal constructor: (@name) -> super @meowed = 0 meow: => ++@meowed bark: -> throw Error 'unimplemented' play: -> setInterval @meow, 5000 |
class exports.Cat extends Animal (@name) -> super ... @meowed = 0 @meow = ~> ++@meowed bark: -> ... play: -> setInterval @meow, 5000ms |
switch day when "Fri", "Sat" if day isnt rainy go bingo go dancing when "Sun" then go church else go work |
switch day case \Fri \Sat if day is not rainy go bingo go dancing case \Sun then go church default go work |
|
/*
|
RegExp /// he (re){1,2} gex ///.source, flag |
// he (re){1,2} gex #flag //? |
I2 = [ [1, 0] [0, 1] ] dicts = [ foo: 0 bar: 1 , 'baz qux': 2 ] assert dicts[1]['baz qux'] is 2 |
I2 = dicts =
assert dicts.1.'baz qux' is 2 |
child = new class extends prototype: parent child.x = 6 child.y = 9 |
child = ^parent <<< x: 6, y: 9 |
options = {} options[k] = v for own k, v in defaults options[key] = value run options |
run {...defaults, (key): value} |
Array(-~num).join str |
"#str" * num |