> From: Allen Wirfs-Brock <[email protected]>
> Date: July 18, 2011 19:32:24 GMT+02:00
> To: es-discuss <[email protected]>
> 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
[email protected]
twitter.com/rauschma
home: rauschma.de
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss