new <Object>

Axel Rauschmayer axel at rauschma.de
Tue Oct 11 12:58:42 PDT 2011


> I dont think having both new <Object> and new <Function> in the language will cause any conflicts. It's the same as claiming that having both declarative class and new <Function> would cause "confusion". 

I wouldn’t mind either, but there *will* be two ways of doing things then (and that’s only a positive in the Perl world ;-).

> class literals look the same but literal declaration are a right pain for any kind of meta programming. I can't take an existing object and turn it into a "class" without using eval.

Can you elaborate?

It don’t think, it is that bad: Currently, you have a clear separation of concerns between the prototype and the constructor. However, these things are cumbersome:

1. Assembling a class
2. Subclassing
3. Constructor chaining, super method calls
4. Instanceof works with a name of an entity that only existed at instantiation time and is only weakly connected to an instance after that.

Sect. 3 in [1] goes into more detail on how prototypes-as-classes would automatically make these things simpler.

But in ECMAScript.next, class literals and super references fix 1-3 (and #4 is not that hard to live with). Superficially, things will be easy to handle. Under the hood, it’s a little more complicated, but it should help to concentrate on what role the constructor function plays and what role the prototype.

[1] http://www.2ality.com/2011/06/prototypes-as-classes.html
-- 
Dr. Axel Rauschmayer

axel at rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111011/2ee97814/attachment.html>


More information about the es-discuss mailing list