jashkenas/coffee-script — pull request #2599 by epidemian (2012-10-28 12:22:13+00:00)
Title: Issue #2359 fix: avoid "other typed" constructors

Here's an attempt to fix #2359.

I opened the original issue quite long ago, but procrastinated ad-infinitum after feeling intimidated with `nodes.coffee`. #2596 encouraged me to give it another shot :)

This pull request basically re-introduces the ability to extend native objects without defining a constructor:

```coffeescript
class MyError extends Error
console.log new MyError instanceof MyError # -> true

class Foo extends Object
console.log new Foo instanceof Foo # -> true
```

And also forbids returning any value from the constructor. This throws a SyntaxError:

```coffeescript
class Foo
constructor: ->
return 5
```

Empty returns are allowed though:

```coffeescript
class Foo
constructor: ->
if mustReturnEarly
return # OK
@doSomeWork()
```

This is, however, at the expense of losing the ability to define "other typed" constructors. That is, constructors that return objects other than `this`. So it's a backward-incompatible change ([one test](https://github.com/jashkenas/coffee-script/blob/40431241357e04bda357e59139c2d8403102feb4/test/classes.coffee#L598-601) had to be removed).