Created
December 1, 2011 20:50
-
-
Save jait/1419765 to your computer and use it in GitHub Desktop.
CoffeeScript class demo
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
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