On Jul 19, 2011, at 6:12 PM, Gavin Barraclough wrote:
> On Jul 19, 2011, at 12:17 PM, Allen Wirfs-Brock wrote:
>> One issue is that <| conceptually modifies the [[Prototype]] of its RHS. As
>> an operator (whether special character or keyword based) we can restrict the
>> RHS to be a literal and define the behavior such that no actual mutation of
>> [[Prototype]] is necessary.
>>
>> However, at the value level we have no way to distinguish an object that was
>> created via a literal and which has no references other than the current
>> argument value. So, when we specify Object.make we have to accept an
>> arbitrary object as the second argument and specify either [[Prototype]]
>> mutation or some sort of shallow copy, either of which can be problematic.
>>
>
> On Jul 19, 2011, at 1:27 PM, Brendan Eich wrote:
>> We are *not* gonna standardize mutable [[Prototype]].
>
>
> The concept of an operator that logically modifies the RHS operand seems
> unfortunate,
L <| R does not modify R's [[Prototype]] so much as "preset" it, since R is
grammatically restricted to be a literal form (object, array, regexp, etc.).
> as does having an operator with an implicit requirement that the RHS be a
> literal. The fact that the only reason that setting the prototype is
> acceptable to us is because the RHS is a literal seems to raise the question
> whether this really should be the action of an operator? Do we not just need
> an extension to the object/array literal syntax to allow the prototype to be
> specified within the literal?
>
> Some engines already allow syntax to declare a prototype for an object
> literal, e.g.:
>
> var o = { __proto__: protoObj, a:1, b:2 };
>
> Does this produce the same results as:
>
> var o = protoObj <| { a:1, b:2 };
>
> ?
Yes.
> I'm sure that we don't want to standardize __proto__, perhaps an option
> closer to the spec would be:
>
> var o = { [[Prototype]]: protoObj, a:1, b:2 };
>
> Though I'm sure this isn't particularly lovable syntax, particularly if we
> want to support this for array literals.
> Maybe something based on the idea of the <| operator might work?, say:
>
> var o = { |> protoObj, a:1, b:2 };
>
> Apologies in advance if I'm missing an understanding of an important detail
> of the <| operator as proposed.
Part of the appeal of <| is that it lets us write class-like expressions:
class D extends B { ... }
vs.
let D = B <| { ... }
but this led down the prototype-first (B and D name prototype objects, not
constructors) naming path, which I think is too different from current
constructors-with-prototypes JS pattern. It also led to the class body is
object literal idea, which I've been arguing against just today.
There are lots of plausible syntactic extensions for presetting [[Prototype]],
but they all need enforcement that the right-hand side of <| (or the equivalent
position for alternative syntaxes) is new and not yet accessible to code.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss