Created
November 4, 2012 05:25
-
-
Save starkhorn/4010430 to your computer and use it in GitHub Desktop.
New person with hash and block 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
class Person | |
constructor: (args) -> | |
if typeof args is "function" | |
args.call this | |
else | |
@[key] = val for key, val of args | |
about: -> | |
"My name is #{@name}, I am #{@age}" | |
me = new Person -> | |
this.name = "Ohm" | |
this.age = 25 | |
anotherMe = new Person | |
name: "Ohm" | |
age: 25 | |
console.log "About me => #{me.about()}" | |
console.log "About another me => #{anotherMe.about()}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment