Skip to content

Instantly share code, notes, and snippets.

@8bitDesigner
Created June 2, 2014 23:57
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 8bitDesigner/15295fcd2b8216cf0bde to your computer and use it in GitHub Desktop.
Save 8bitDesigner/15295fcd2b8216cf0bde to your computer and use it in GitHub Desktop.
class Foo
bar: -> 'bar' # Defining an instance method
Foo::baz = -> 'baz' # Appending an instance method on the class prototype
Foo.bacon = -> 'tasty' # Definining a method on the class itself
# Instance methods
foo = new Foo()
foo.bar() # bar
foo.baz() # baz
foo.bacon() # undefined
# Static methods
Foo.bacon() # tasty
Foo.bar() # undefined
Foo.baz() # undefined
@8bitDesigner
Copy link
Author

And the static/instance methods can have the same name:

class Foo
  bar: -> 'instance bar'

Foo.bar = -> 'static bar'


foo = new Foo()
foo.bar() # instance bar
Foo.bar() # static bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment