Non-extensible WeakMaps

Herby Vojčík herby at mailbox.sk
Sun Jan 22 11:42:31 PST 2012


David Bruant wrote:
> I agree that Object.preventExtensions is defined as preventing addition
> of new properties. Likewise, Object.freeze and Object.seal only act on
> object properties (extended to private properties?).
> But the broader problem they are addressing is reducing the mutability
> of objects. WeakMaps, maps and sets bring a new form of mutability which
> cannot be implemented in the form of private properties (I think at
> least). So the question is:
>
> Should Object.preventExtensions be extended to reduce WeakMaps, Maps and
> Sets mutability? Likewise for Object.seal|freeze?

It would be special case. I'd say no.
Collections should proabably get their own API for this, analogic to 
Object.preventExtension|seal|freeze.

Where to put it, is the question. It should probably be callable like 
Map.seal(aMap), Array.freeze(anArray) etc. If a collection hierarchy has 
common ancestor, constructor function can inherit in parallel with 
prototypes, so it may in fact reside in that(ose) common base classes.

> David

Herby

P.S.: Array.xxx version should be able to work only on indexed elements, 
not or other properties (it is Object.xxx's work). Of course them same 
for Map etc., but there it is natural.


More information about the es-discuss mailing list