Skip to content

side by side comparison

balupton edited this page Jan 18, 2013 · 54 revisions
CoffeeScript Coco
last = (a) -> a[a.length-1]
class equals
  constructor: (args...) -> return args[0] is args[1]
last = -> it[*-1]
function equals
  @@0 === @@1
$('.account')[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] by 1
    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
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
mixin = (objects...) ->
  for obj in objects
    @[key] = val for own key, val of obj
  this
mixin = (...objects) ->
  for objects => @ <<< &
  this
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
(->
if match = /\d+/.exec location.hash
@value = match[0]
@focus()
else
@disabled = yes
).call document.getElementById 'page'
let this = document.getElementById \page
if /\d+/exec location.hash
@value = that.0
@focus!
else
@disabled = true

  • Released under the MIT License

/*
  • Released under the MIT License */
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 =
  • I2:
    • 1 0
    • 0 1
  • 'baz qux': 2 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 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
    
    options = clearStyle: true, collapsible: true, active: false
    
    options = {+clearStyle, +collapsible, -active}
    
    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]
    
    Clone this wiki locally