An "extend" operator is a natural companion to <|

Axel Rauschmayer axel at rauschma.de
Mon Jul 18 19:24:59 PDT 2011


> From: Allen Wirfs-Brock <allen at wirfs-brock.com>
> Date: July 18, 2011 19:32:24 GMT+02:00
> To: es-discuss <es-discuss at mozilla.org>
> Subject: An "extend" operator is a natural companion to <| 


Definitely a nice dual to <|

> proto <| obj


What happens if obj is not a literal? Then it would make sense to do a shallow copy of obj whose prototype is proto. That would be useful for combining objects into a chain.

From your examples, it looks as if the lhs would be modified, a bit similar to the += operator. Then the "arrow" should probably point in the opposite direction, e.g.:

> objToBeModified +> increment


Quoting from your examples:

> function Point(x,y) {
>    return tthis <& {
>                   __x: x,
>                   __y: y
>                  };
> };
> Point.prototype <& {
>    __validate(x,y) { return typeof x == 'number' && typeof y = 'number'}
> };


I love how the prototype is incremented here. What does "tthis" do? Wouldn't point simply return an object literal (no "this <&")?

Another example from your message:

> const Point = {
>      //private members
>      __x: 0,
>      __y: 0, 
>      __validate(x,y) { return typeof x == 'number' && typeof y = 'number'},
>      //public members
>      new(x,y) {
>           if (!this.__validate(x,y)) throw "invalid";
>           return this <| {
>                   __x: x,
>                   __y: y
>                  }
>       };
> }

If things are ever done this way, I would prefer to have an initialize() method (that only initializes an instance that has been created for it) and not a method that instantiates and initializes at the same time. initialize() works together very well with super-references, because in subclasses, you simply call the super-initialize method.

-- 
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/20110719/6c793e4b/attachment.html>


More information about the es-discuss mailing list