The class operator: a bridge between object and function exemplers

Axel Rauschmayer axel at rauschma.de
Thu Nov 17 12:04:20 PST 2011


I agree with the advantage of a declaration containing a name and with it being similar to functions.

I tried a synthesis of the current inheritance/class proposals: https://gist.github.com/1374226

Comments welcome; it might please nobody by trying to please everybody.

On Nov 17, 2011, at 20:20 , Russell Leggett wrote:

> On Thu, Nov 17, 2011 at 12:04 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> OK, I have a fix for the missing constructor problem. See: http://wiki.ecmascript.org/doku.php?id=strawman:class_operator#missing_constructors 
> 
> 
> The biggest thing I see missing is a declarative form that includes the name. I just think its so close, that to not include a form
> 
>     class Point {...}
> 
> Which can desugar to create a var Point at the very least, would be a bit of a tragedy. I think most people will see the class operator and think about it as analogous to function.
> 
> Another piece which might not be as big a deal is that [[ctor]] is not the same as 'constructor', and in the cases with a missing 'constructor', the result of 'class Proto' would seem like it makes (or fetches) a function that behaves like a proper constructor function, but it will result in an instance whose prototype does not have an own 'constructor' property. (I think I even confused myself with that, sorry)
> 
> The alternative proposal I've been advocating that always creates a new function and prototype makes tradeoffs in the other direction. It does not require [[ctor]], or automatic .prototype references from constructor to the enclosing object literal. It also makes it trivial to include a name on the constructor function without mutation (because a new function is being made). OTOH, because it always creates a new function with a fresh prototype that points up to UnaryExpression, you get this important difference:
> 
>     let f = new Foo();
>     let isSame = (class f === Foo);
>     //isSame is true for allen's proposal, but false for mine.
>     //however, mine would behaviorally be the same (barring serious inspection)
> 
> At this point, if Allen's proposal included a declaration form 'class Point {...}' I would be ready to get behind it. I still have a fondness for mine, which is used purely for defining classes, but for most cases, his would work equally well in the ways I would want to use it.
> 
> - Russ
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111117/182b456c/attachment.html>


More information about the es-discuss mailing list