Skip to content

side by side comparison

Gavin Haynes edited this page Oct 11, 2019 · 54 revisions
CoffeeScript Coco
last = (a) -> a[a.length-1]
last = -> it[*-1]
class equals
  constructor: (x, y) -> return `x == y`
function equals
  @@0 == @@1
$('.account')
  .addClass('active')
  .show 'slow'
$ \.account
  .addClass \active
  .show \slow
pythagoras = []
for a in [9..1]
  for b in [a...99] by 1
    h = (a*a + b*b) ** 0.5
    pythagoras.push [a, b, h] unless h % 1
pythagoras =
  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 file, index in ['head', 'body', 'tail']
  do (file, index, time = new Date) =>
    fs.readFile file, (err, contents) =>
      @compile file, index, contents, time
for let file, index of <[head body tail]>
  let time = new Date
    err, contents <~ fs.readFile file
    @compile file, index, contents, time
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'
export class 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 = (com.github ||= {}).satyr ||= []
pages = com@github@@satyr
options = collapsible: true, active: false
options = {+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