Skip to content

Instantly share code, notes, and snippets.

@jait
Created December 1, 2011 20:50
Show Gist options
  • Save jait/1419765 to your computer and use it in GitHub Desktop.
Save jait/1419765 to your computer and use it in GitHub Desktop.
CoffeeScript class demo
class Contact
constructor: (@name) ->
@_type = "org.foo.contacts.Contact"
addPhone: (phone) =>
if not phones?
@phones = []
@phones.push phone
dump: =>
console.log JSON.stringify(this)
class Name
constructor: (@prefix, @firstName) ->
class Phone
constructor: (@value, @subType=`undefined`) ->
c = new Contact(new Name("Dr", "Palle"))
c.addPhone new Phone("1234")
alert JSON.stringify(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment