Could <| be spelled "extends"?

Axel Rauschmayer axel at rauschma.de
Fri Feb 1 14:21:59 PST 2013


How about a new version of Object.create, e.g. Object.make? Roughly:

Object.make = function (proto, props) {
	return props ? Object.create(proto, Object.getOwnPropertyDescriptors(props)) : Object.create(proto);
};
// with Object.getOwnPropertyDescriptors() having the obvious definition

Result:

let p = Proxy(target, Object.make(VirtualObject, {
     get(key, receiver) {...},
     set(key,value, receiver) {...}
}));

Going purely by gut feeling, I would put `extends` in the realm of constructor inheritance and would be confused to see it used on objects. I’d expect `extends VirtualObject` to be an anonymous class (=constructor).

On Feb 1, 2013, at 22:02 , Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:

> Friday afternoon dreaming...
> 
> Now that we have introduced class declarations, I occasionally discover situations where I need to create a singleton specialization of some class. One way to do that is to apply a new operator to an anonymous class expression.  For example,
> 
> let p = Proxy(target, new class extends VirtualObject {
>      get(key, receiver) {...}
>      set(key,value, receiver) {...}
> });
> 
> Now this is a pretty heavy weight mechanism.  It creates both a constructor function and a prototype object in addition to the the actual instance object that is all I really want to create.
> 
> Back when we were considering the <| operator the above might have been expressed as
> 
> let p = Proxy(target, VirtualObject <| {   //the proposed semantics made VirtualObject.prototype the [[Prototype]] of the obj lit
>      get(key, receiver) {...},
>      set(key,value, reciever) {...}
> });
> 
> Which is both more concise and which only creates a single instance object rather than a constructor/prototype/instance triad. Something like this can still be expressed in the current draft of ES6 as:
> 
> let p = Proxy(target, {
>      __proto__:  VirtualObject.prototype,
>      get(key, receiver) {...},
>      set(key,value, reciever) {...}
> });
> 
> This is ugly in its use of __proto__ and unreliable because __proto__ can be removed from Object.prototype.  Object.create is another ugly way to express something like this.
> 
> The class express idiom got me thinking about another alternative.  Note that "extends" has always been an ES FutureReservedWord.  That means that using "extends" without a preceding "class" keyword won't break any existing code. Perhaps we could express this example like:
> 
> let p = Proxy(target, extends VirtualObject {
>      get(key, receiver) {...},
>      set(key,value, receiver) {...}
> });
> 
> "extends" that isn't part of a class declaration would be a prefix operator defined like:
> 
> PrimaryExpression ::
>   ...
>   extends Expression ObjectLiteral
> 
> a desugaring semantics might be:
> 
> Object.mixin(new (Expresion), ObjectLiteral)
> 
> Allen
> 
> 
> _______________________________________________
> 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/20130201/7c138890/attachment-0001.html>


More information about the es-discuss mailing list