Skip to content

Instantly share code, notes, and snippets.

@michrome
Last active December 18, 2015 19:19
Show Gist options
  • Save michrome/5831920 to your computer and use it in GitHub Desktop.
Save michrome/5831920 to your computer and use it in GitHub Desktop.
Playing with classes in CoffeeScript
# Run this http://cl.ly/PnKK
class Animal
constructor: (options) ->
{@name, @sound, @action} = options
greeting: ->
"#{@sound} #{@sound}"
dog = new Animal({sound:"woof", name:"Rover", action:"wags tail"})
class Description
constructor: (@animal) ->
text: ->
# Invisible comment
###
Visible comment
###
"#{@animal.name} says “#{@animal.greeting()}” and #{@animal.action}!"
description = new Description(dog)
alert "#{description.text()}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment