1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/documentation/sections/breaking_changes_super_this.md
Geoffrey Booth cbc695b831 2.0.2 (#4758)
* Give the notes about `super` and `this` their own section in the docs

* 2.0.2 changelog

* 2.0.2 release output

* Rewrite
2017-10-26 18:29:45 -07:00

595 B

super and this

In the constructor of a derived class (a class that extends another class), this cannot be used before calling super:

class B extends A
  constructor: -> this  # Throws a compiler error

This also means you cannot pass a reference to this as an argument to super in the constructor of a derived class:

class B extends A
  constructor: (@arg) ->
    super @arg  # Throws a compiler error

This is a limitation of ES2015 classes. As a workaround, assign to this after the super call:

codeFor('breaking_change_super_this')