On Oct 1, 2011, at 8:23 PM, Axel Rauschmayer wrote:
> ...
> 
> What do you think about the following variation of Allen’s pattern?
> 
>    const ClassName = SuperClass <| function(/*constructor parameters */) {
>        //constructor body
>        super.constructor(/*arguments to super constructor */);
>        this.{
>            // per-instance properties
>        };
>    }.{
>        prototype: {
>            // methods
>        },
>        // class (ie, constructor) properties
>    }
> 
> Requirement: The .{} operator extends recursively if there is a name clash. 
> Otherwise, the prototype cannot be extended this way.
> 

+1

Your last requirement is the rub.  As currently defined,
     prototype: { ...}
would replace the value of the constructor's 'prototype' property which would 
mess up the implicit constructor/prototype wiring.  Defining : to mean .{ if 
the property already exists seems fragile and precludes the possibility of 
using .{ to replace property values.  But, what if we allow:
    propName.{ ...}
to occur in a PropertyAssignment position of an object extension literal.  Then 
the pattern could be:

const ClassName = SuperClass <| function(/*constructor parameters */) {
       //constructor body
       super.constructor(/*arguments to super constructor */);
       this.{
           // per-instance properties
       };
   }.{       
       prototype.{    //  <<<<< note . instead of :
           // methods
       },
       // class (ie, constructor) properties
   };

It's only a one character change but it eliminates the hazard that some people 
are concerned about of leaving off the .constructor or .constructor.{...} at 
the end of the pattern.  Also, I can imagine that "recursive stache"  (hey, 
it's inevitable that "mustache" will get contracted to "stache") would be 
useful in other situations. Personally, I find this new pattern not quite as 
"pretty" than my original proposal (it's less symmetric/ more irregular hence 
probably harder to learn and remember) but I'd still be happy to use it.

If we could actually agree to this, then we could move on to making sure that 
the new operator did the right thing for non-function object and then we really 
would have a complete set of primitives that  nicely and interoperability 
supported both classical and prototypal inheritance abstractions. 

Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to