Scoped binding of a method to an object

Erik Arvidsson erik.arvidsson at gmail.com
Sun Oct 13 13:26:05 PDT 2013


On Oct 13, 2013 3:23 PM, "Brendan Eich" <brendan at mozilla.com> wrote:
>
> Erik Arvidsson wrote:
>>
>> Let's not kid ourselves. WeakMaps have bad user ergonomics and runtime
ergonomics. I think at this point non method functions are much better.
>
>
> Hang on, relationships and new syntax can solve both performance and
ergonomics concerns, we think.
>
> Perhaps you missed the March meeting where Mark discussed relationships
(big meeting, it may have been near or even over a break).

I did not miss it.

> The key insight is that with:
>
>   obj at rel
>   obj at rel = val
>
> we can avoid the "dot dilemma" of having to parameterize by scope,
instead treat these two as
>
>   rel.@@get(obj)
>   rel.@@set(obj, val)
>
> respectively, under the hood.
>
> Mark observed further that where rel could be a weak map, it should not
be implemented as an ephemeron table with all the GC costs that entails.
Because such an "object field" relationship outlives all object instances,
it is equivalent to a class or trait private member, and the value can be
stored directly on the object.

Using a WeakMap for rel is a bit too simplistic. We need to read and write
through to the prototype but you are right that rel can be implemented
using WeakMaps.

> The issue of proxy leaking is dodged by delegating to rel, which can
itself by proxied in a membrane setting, IIRC.
>
> But at this point I should summon Mark to take over. My point is that it
seems not everyone heard Mark's statement that weakmaps should not be used
to implement relationships except in preprocessors targeting ES6 (assuming
we get relationships into ES7).

Exactly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131013/81886310/attachment.html>


More information about the es-discuss mailing list