strawman for the := operator

Brendan Eich brendan at mozilla.org
Wed Aug 8 09:35:26 PDT 2012


Erik Corry wrote:
> Hi
>
> This proposal offers a way to get around some of the strange semantics
> of '=', specifically the way read-only properties and setters on
> objects in the prototype chain can restrict what you can do on the
> receiver of an assignment.

This is "strange" only insofar as you can't say what you mean if you 
want to override. There's no law of nature requiring = to override, though.

Assigning != defining in ES5, even in reality in fixed implementations 
of ES3, and in truth going back to the first JS implementation: 
proto-setters (internal, hidden) are invoked by assignment, readonly 
proto-props prevent = being used to override on a delegating object 
(silent failure, of course, due to lack of try/catch).

What I'm getting at: is assignment != defining strange, or is the lack 
of expressiveness that left JS with = but not := strange, or is = not 
defining strange? I didn't want to assume the last was what you meant, 
since it is not obvious and not the only possible strangeness or asymmetry.

>    However it has some strangeness itself:
>
> * There is little point in having read-only properties if the common
> way to do assignment is :=.  := will just walk all over a read-only
> property.

No, readonly properties must be {writable: false, configurable: false} 
to have integrity, and := cannot redefine a non-configurable property.

> * Copying private members from one object to another violates the
> encapsulation pretty badly.  You would hope that using private names
> allowed you to easily reason about which objects have which
> properties, just by looking at the limited number of places a private
> name is used.  But with this any code in the system that has two
> instances of a class can splat object a's private properties with
> those from object b.  It's rather like a replay attack in crypto.

Yes, this is an open issue in my view. If one uses a private name to 
brand an object, attackers who have access to such an object can use := 
to forge trojan objects.

> * I don't understand the super stuff.

Allen should field this one.

/be


More information about the es-discuss mailing list