mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
d1d2c16fdd
* Update classes docs for CS2 * Port breaking changes from https://github.com/jashkenas/coffeescript/wiki/%5BWIP%5D-Breaking-changes-in-CoffeeScript-2 into new docs section * Update browser compiler * Update re @connec’s notes; split classes section into two sections for classes and working with prototypes; make breaking changes examples editable whenever possible
688 B
688 B
Classes
CoffeeScript 1 provided the class
and extends
keywords as syntactic sugar for working with prototypal functions. With ES2015, JavaScript has adopted those keywords; so CoffeeScript 2 compiles its class
and extends
keywords to ES2015 classes.
codeFor('classes', true)
Static methods can be defined using @
before the method name:
codeFor('static', 'Teenager.say("Are we there yet?")')
Finally, class definitions are blocks of executable code, which make for interesting metaprogramming possibilities. In the context of a class definition, this
is the class object itself; therefore, you can assign static properties by using @property: value
.