Scoped binding of a method to an object

Brendan Eich brendan at mozilla.com
Sun Oct 13 12:23:00 PDT 2013


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

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.

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

/be


More information about the es-discuss mailing list