Skip to content

Instantly share code, notes, and snippets.

helloWorld = (street = "Lille") -> console.log "Hello world from #{street}."
helloWorld()
# Hello world from Lille.
helloWorld("Paris")
# Hello world from Paris.
f = (a, b..., c) ->
f("a", "foo", "bar", "baz", 42)
# b => [ 'foo', 'bar', 'baz' ]
f("a", 42)
b # []
[a..., b] = ["foo", "bar", 42]
a # [ 'foo', 'bar' ]
window.App = class App
person = { firstname: "Martin", lastname: "Catty" }
person.introduce = -> console.log "Bonjour, je suis #{@firstname} #{@lastname}."
person.introduce()
# Bonjour, je suis Martin Catty.
setAttribute = (attribute) -> @attribute = attribute
setAttribute = (@attribute) ->
registerEvents = (node) ->
node.bind "click", (event) =>
# this est bindé sur le this avant l'appel et non sur l'event
window.Animal = class Animal
window.Dog = class Dog extends Animal
# convention pour une constante mais utilise var
STATES = ["sleeping", "eating"]
constructor: ->
# appelle le constructeur d'Animal
super