Le 30/10/2011 01:34, Axel Rauschmayer a écrit :
> http://wiki.ecmascript.org/doku.php?id=harmony:object_extension_literal_class_pattern
>
>     const className = superClass <| function(/*constructor parameters */) {
>         //constructor body
>         super.constructor(/*arguments to super constructor */);
>         this.{
>          //per instance property definitions
>         };
>     }.prototype.{
>         //instance properties defined on prototype
>     }.constructor.{
>         //class (ie, constructor) properties
>     };
>
> The main problem is that obj.prototype.{...} does not evaluate to obj
I wonder if the "only one semicolon" obsession is really worth it. Consider:
-----
const className = superClass <| function(/*constructor parameters */) {
        //constructor body
        super.constructor(/*arguments to super constructor */);
        this.{
         //per instance property definitions
        };
    };

className.prototype.{
    // prototype properties
};

// and if really necessary:
/*className.{
    // "constructor properties"
};*/
-----

As far as I'm concern, this is declarative enough:
1) <| provides the proper "super" (why the ".constructor"?) within the
constructor body
2) <| also sets className.prototype.[[Prototype]] to superClass.prototype
3) this.{} to initialize instance properties
4) className.prototype.{} to set prototype properties

Because I write this in 2 instructions (i don't count constructor
properties as I don't see why they're needed), I need to repeat
"className". A dedicated class syntax would avoid this, I admit.

On a side note. <| also sets className.[[Prototype]] to superClass (5).
I still think this is a mistake and that two different operators should
be defined. One operator for 1)+2) and the other for 5).
1)+2) is about constructing the proper object when a function is used as
a constructor
5) is about setting a custom [[Prototype]] to an object (aka
"subclassing"). And as it turns out, functions are objects in
JavaScript, hence the ambiguity of the operator.
The way I see it, the operator for 1) and 2) would throw if the RHS is
not a function expression.

Thoughts on this last point?

David
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to