Jyve CoffeeScript

CoffeeScript is a little language that compiles into JavaScript.

In [ ]:
# Assignment:
@number   = 42
@opposite = true
In [ ]:
# Conditions:
@number = -42 if @opposite
In [ ]:
# Functions:
@square = (x) -> x * x
In [ ]:
# Arrays:
@list = [1, 2, 3, 4, 5]
In [ ]:
# Objects:
@math =
  root:   Math.sqrt
  square: @square
  cube:   (x) -> x * @square x
In [ ]:
# Splats:
@race = (winner, runners...) ->
  print winner, runners
In [ ]:
# Existence:
alert "I knew it!" if elvis?
In [ ]:
# Array comprehensions:
cubes = (@math.cube num for num in @list)
In [ ]:
class Animal
  constructor: (@name) ->

  move: (meters) ->
    alert @name + " moved #{meters}m."

class Snake extends Animal
  move: ->
    alert "Slithering..."
    super 5

@Snake = Snake
In [ ]:
@sam = new @Snake "Sammy the Python"
In [ ]:
@sam.move()