Last active
December 18, 2015 19:19
-
-
Save michrome/5831920 to your computer and use it in GitHub Desktop.
Playing with classes in CoffeeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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