Skip to content

Instantly share code, notes, and snippets.

@gkop
Created January 29, 2014 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkop/8681995 to your computer and use it in GitHub Desktop.
Save gkop/8681995 to your computer and use it in GitHub Desktop.
Dog class in coffee
class Dog
age: ->
@human_age * 7.002
my_dog = new Dog()
my_dog.human_age = 4.5
my_dog.name = "Stewie"
my_dog.greeting = ->
"Woof! I'm #{this.name}"
jasons_dog = new Dog()
jasons_dog.human_age = 4
jasons_dog.name = "Simba"
jasons_dog.greeting = ->
"Bow wow! My name's #{@name}"
for dog in [my_dog, jasons_dog]
console.log("#{dog.name} is #{dog.age()} years old. #{dog.greeting()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment