Proposal: Abstract References

Tab Atkins Jr. jackalmage at
Wed Oct 22 16:05:50 PDT 2014

On Wed, Oct 22, 2014 at 1:12 PM, Isiah Meadows <impinball at> wrote:
> I know that this could clearly work for implementing private arrays, etc. as
> well, but what about private integer or booleans?
> ```js
> let _x = 0;
> let _y = false;
> class Foo {
>   constructor(x, y) {
>     this::_x = x;
>     this::_y = y;
>   }
>   // ...
> }

You misunderstand the proposal a bit.  In `x::y`, the y is an object
that is asked to respond in a special way.  When `y` is a WeakMap, it
responds to `x::y = z;` by calling `y.set(x, z)` on itself.

You can store whatever you want in there; the `z` value can be
anything, including numbers or booleans.  But the `y` object needs to
be something that knows how to respond to the bind operator.

(Similarly, if `y` is a function, by default it responds to `x::y(z)`
by calling itself with its `this` set to `x`.  This makes it act
similarly to `x.y(z)`, but without having to actually define `y` as a
property on `x`.)


More information about the es-discuss mailing list