Jason Orendorff jason.orendorff at gmail.com
Thu Jun 19 05:14:21 PDT 2014

On Wed, Jun 18, 2014 at 4:09 PM, Allen Wirfs-Brock
<allen at wirfs-brock.com> wrote:
>> Jason covered the combinations: his proposal supports class subclassing function, etc. What concretely do you mean here, if not that? If you mean refactoring from one to the other, what observably differs?
> My understanding of the proposal was that:
> class F  {constructor(x) {this.foo=x}};
> turns into the equivalent of:
> function F(x) { /* ??? the initial message really isn't explicit about what does here */ };
> F[Symbol.new] = {[Symbol.new](x) {  //use an object literal to create a "method" kind of function
>     var obj = super();
>     obj.foo = x
>     }}[Symbol.new].toMethod(F);
> which is quite different from you get for:
>  function F(x) {this.foo=x};

But again, what user-observable difference are you pointing to? `new
F(0)` in either case creates a new object inheriting from F.prototype,
sets that object's "foo" property to 0, and returns that object.
Subclassing either one is just `class G extends F {...}`.

As a side note, just because you can write something in a complicated
way doesn't necessarily mean it's complicated. I think having `F()`
and `new F()` do the same thing is simpler for users than having them
do different things. Having a single hook for object creation is
simpler than having two (like C++) or three (like Ruby and Smalltalk).

`function F(x) {this.foo=x}` is short, not simple.


More information about the es-discuss mailing list