jashkenas/coffee-script — pull request #3224 by marchaefner (2013-10-29 00:07:57+00:00)
Title: Minor fixes for class compilation

* Don't put `__extends` call above directive prologue.

* (Partial) fix for #3008: Don't add unnecessary `_ref` for implicit calls to super / external constructor (see discussion below). Plus some code simplification.

#### Discussion

An implicit call to super is only generated when no constructor exists.

Method bindings must happen before the implicit call to super or an external constructor:

* It's been like that since (at least) 9a5546c8 (except for 1.6.0)
* The superclass's or external constructor should be able to use overwritten methods (that are properly bound).
* Otherwise the superclass would have to iterate over the prototype chain to determine which methods will be bound later on by any subclass constructors.
* A class without a constructor should behave as if the constructor was
`-> super`

Given the above points (and contrary to a previous [comment](https://github.com/jashkenas/coffee-script/issues/3008#issuecomment-18802022)): The implicit call to super / external constructor is always the last expression. This allows the removal of `_ref`, circumventing any scope issues.

Still to fix:

* The `_class` reference to an external constructor is leaking into the outer scope. (See comments in #3008.)

* Binding is done unconditionally. Bound methods that were overridden in subclasses are wrapped multiple times. (It is also not possible to override a bound method with an unbound one.)