-
Notifications
You must be signed in to change notification settings - Fork 48
side by side comparison
satyr edited this page Dec 15, 2011
·
54 revisions
CoffeeScript | Coco |
---|---|
last = (a) -> a[a.length-1] class equals constructor: -> return `arguments[0] == arguments[1]` |
last = -> it[*-1] function equals @@0 == @@1 |
$('.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 a*a + b*b pythagorases.push [a, b, h] unless h % 1 |
pythagorases = for a from 9 to 1 by -1 for b from a til 99 h = (a*a + b*b) ** 0.5 [a, b, h] unless h % 1 |
mixin = (objects...) -> for obj in objects @[key] = val for own key, val of obj this |
mixin = (...objects) -> import obj for obj of objects this |
for filename, index in ['head', 'body', 'tail'] do (filename, index) => timestamp = new Date fs.readFile filename, (err, contents) => @compile filename, index, contents, timestamp |
for filename, index of <[ head body tail ]> let timestamp = new Date err, contents <~ fs.readFile filename @compile filename, index, contents, timestamp |
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 @interval: 5000 meow: => ++@meowed play: -> setInterval @meow, @constructor.interval bark: -> throw Error 'unimplemented' |
class exports.Cat extends Animal (@name) -> super ... @meowed = 0 @meow = ~> ++@meowed @interval = 5000ms play: -> setInterval @meow, ..interval bark: -> ... |
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 //? |
dicts = [ I2: [ [1, 0] [0, 1] ] , 'baz qux': 2 ] assert dicts[1]['baz qux'] is 2 |
dicts =
|
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 of defaults options[key] = value run options |
run {...defaults, (key): value} |
x = !x |
!=x |
Array(-~num).join(str).replace /\D+/g, '' |
"#str" * num - /\D+/g |
biggest = if a > b then a else b |
biggest = a >? b |
pages = ((root.com ||= {}).github ||= {}).satyr ||= [] |
pages = root@com@github@@satyr |
rotate = (point) -> if 0 of point then [point[2], point[0], point[1]] else x: point.z, y: point.x, z: point.y |
rotate = (point) -> if 0 in point then point[2 0 1] else point{x: z, y: x, z: y} |
(String.fromCharCode i for i in [65..90]) |
[\A to \Z] |