Skip to content

Instantly share code, notes, and snippets.

@Anaphase
Created September 21, 2015 16:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anaphase/f73fcd5047d311f1cb62 to your computer and use it in GitHub Desktop.
Save Anaphase/f73fcd5047d311f1cb62 to your computer and use it in GitHub Desktop.
CoffeeScript Class Cheatsheet
class ClassName
# shared via closure over constructor
# class and instance functions have access to this variable
privateVariable = 'privateVariable'
# shared via closure over constructor
# not exposed in instance
# doesn't have access to instance
# @ is the window object
# class and instance functions have access to this function
privateFunction = -> 'privateFunction'
# shared via prototype
classVariable: 'classVariable'
# shared via prototype
classFunction: -> 'classFunction'
constructor: ->
# unique per instance
# not exposed in instance
# only instance functions have access to this variable
instancePrivateVariable = 'instancePrivateVariable'
# unique per instance
# not exposed in instance
# has access to instance as @
# only instance functions have access to this function
instancePrivateFunction = => 'instancePrivateFunction'
# unique per instance
@instanceVariable = 'instanceVariable'
# unique per instance
@instanceFunction = -> 'instanceFunction'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment