Must built-in prototypes also be valid instances? (Was: Why DataView.prototype object's [[Class]] is "Object"?)
allen at wirfs-brock.com
Tue Oct 2 11:08:54 PDT 2012
On Oct 2, 2012, at 10:47 AM, Mark S. Miller wrote:
> Having isFoo succeed on an instance of Bar is correct. But there's another case that's more worrisome:
> Foo foo = new Foo();
> Baz baz = Object.create(foo);
> By Allen's pattern, isFoo will also succeed on an instance of baz. OTOH, were the branding done with a WeakMap or the brandcheck done with an own check....
Yes, you're correct an own property check is needed in isFoo. That is is one disadvantage of use private symbols as brands rather than WeakMaps. On the other hand, if you have many instances that need to be branded I suspect that the distributed symbol based technique is going to have a better performance profile than the WeakMaps. My old GC writer self cringes at the possible perf impact many WeakMaps with large numbers of entries.
More information about the es-discuss