strawman for the := operator

Erik Corry erik.corry at gmail.com
Wed Aug 8 03:58:29 PDT 2012


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.  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.

* 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.

* I don't understand the super stuff.  Is there a typo here?:
MyConstructor.prototype = Object.create(Baz);  //inherit from Bar, not
Foo


On 7 August 2012 00:44, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> Based upon discussions last week in the "July 25, 2012 - TC39 Meeting Notes"
> thread, I've created a new strawman proposal for a := operator.  See
> http://wiki.ecmascript.org/doku.php?id=strawman:define_properties_operator
>
> := is a convient way to copy properties from one object to another or to
> extend an object with new properties.  It combines supports for many of the
> same use cases as the previously proposed "object extension literals" and
> the JSFixed Object.extend proposal.
>
> The most important characteristic of := is that it uses
> [[DefineOwnProperty]] semantics rather than [[Put]] semantics to define
> properties on its target object so it doesn't run into issues with
> assignment to accessor properties or over-riding inherited readonly
> properties. It is also smart about dealing with methods that reference
> super.
>
> Some basic examples:
>
>   target := src;  //define all own properties of src onto target
>
>    //add a method and an accessor to an existing prototype
>   Point.prototype := {
>    plus(aPoint) {return new
> this.comstructor(this.x+aPoint.x,this.y+aPoint.y},
>    get rho() {return Math.sqrt(this.x*this.x+this.y*this.y}
> };
>
>
> Have at it,
>
> Allen
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list