File: classes.md

package info (click to toggle)
coffeescript 2.7.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,608 kB
  • sloc: javascript: 1,273; makefile: 19; xml: 9; sh: 6
file content (15 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## 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`.