time to trim mustache
Brendan Eich
brendan at mozilla.org
Mon Jun 4 09:45:47 PDT 2012
Kevin Smith wrote:
> Thanks Dave,
>
> Of the 3 use cases you mentioned, I think unique names are probably
> sufficient for 1 and 3. For the second use case (an inaccessible
> piece of data associated with an object), would not a weak map also be
> appropriate?
No, WeakMaps have two problems we've covered in this list:
1. Less efficient than private names.
This matters when you can least afford it, and it matters for private
names used to program in the large using objects in JS. WeakMaps require
special GC handling and they're an extra object with internal mutable
state. Private name objects are flat, frozen, and can be optimized a lot
harder.
2. You cannot abstract property access:
function get(obj, prop) { return obj[prop]; }
works with a private name object referenced by prop. No such abstraction
can be done with a weak map.
/be
More information about the es-discuss
mailing list