Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created August 28, 2015 12:23
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 chuck0523/02b97cfb511d80874158 to your computer and use it in GitHub Desktop.
Save chuck0523/02b97cfb511d80874158 to your computer and use it in GitHub Desktop.
# 継承
log = (x) -> console.log x
class User
constructor : (@name) ->
hello : -> log "hello, #{@name}"
class AdminUser extends User
bob = new AdminUser "Bob"
log bob.name
bob.hello()
# Bob
# hello, Bob
# オーバーライドも可
class SuperUser extends User
hello : ->
log "sudo "
super()
judy = new SuperUser "judy"
judy.hello()
# sudo
# hello, judy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment