Skip to content

Instantly share code, notes, and snippets.

@senritsu
Last active August 29, 2015 14:21
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 senritsu/06e57307799e4490e432 to your computer and use it in GitHub Desktop.
Save senritsu/06e57307799e4490e432 to your computer and use it in GitHub Desktop.
difference between static and bound class variables
class Test
staticVar = 0
boundVar: 0
# @::boundVar = 0
# this::boundVar = 0
increment: ->
staticVar += 1
@boundVar += 1
read: -> "static: #{staticVar}, bound: #{@boundVar}"
a = new Test
b = new Test
a.increment()
alert "a > #{a.read()}\nb > #{b.read()}"
console.log "a > #{a.read()}\nb > #{b.read()}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment