Question: TypeScript and CoffeeScript both use an `__extends` function to setup inheritance. Here's the one form TypeScript (CoffeeScript's is very similart).

```
var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};

```

Why do they need `function __()` (`function ctor()` in CoffeeScript)? Why not set the prototype directly:

```
var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];

    d.prototype = new b();
};

```

Answer: 
These three lines a): 

```
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();

```

Are *almost exactly* equivalent to b): 

```
    d.prototype.__proto__ = b.prototype;

```

And the reason why a) is prefferred is because `__proto__` is non standard.

I say *almost exactly* because in a.) constructor is enumerable where as in b.) it is not modified and therefore stays the way it is (non-enumerable). A better implementation would use `Object.create` but that is unavailable in ES3 (which is still a compile Target for TypeScript).
John Resig may have answered this in his [Simple Javascript Inheritance](http://ejohn.org/blog/simple-javascript-inheritance/).

> 
> What’s challenging about this, though, is that all we really want is the benefits of ‘instanceof’, not the whole cost of instantiating a Person object and running its constructor.
> 
> 
> 

By creating an intermediate `ctor` or `__` object, the `__extends` method does not have to call the base class constructor to just to setup the prototype!