Yes, if you use weak sets in combination with private symbols you can more or less emulate weak maps. But why not just use weak maps in that case?
From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Gary Guo Sent: Sunday, December 21, 2014 07:26 To: es-discuss@mozilla.org Subject: RE: Proposal About Private Symbol Oops, I forget the WeakSet. So seems my private symbol proposal can work now. Under very deliberately design, private symbol can be used as private field. ```js var constructor=function(){ 'use strict'; var allObjects=new WeakSet(); var privateSymbol=Symbol('private', true); var ret=function(){ if(this===undefined)throw Error('Invalid Construction'); this[privateSymbol]=1; allObjects.add(this); } ret.prototype.set=function(sth){ if(!allObject.has(this))throw Error('Invalid Call'); this[privateSymbol]=sth; // Now this can be called safely, no more worry about leak to Proxy } ret.bind(undefined); } ``` On Sun, 21 Dec 2014 12:30:46 +0100, Michal Wadas <michalwa...@gmail.com<mailto:michalwa...@gmail.com>> wrote: >> But this is not the core of the problem. The problem is the Proxy introduced >> in ES6 enables an object to capture and override almost any operation on an >> object. Without operation on object, it becomes very costly (by using an >> Array of created objects and compare each of them) to identify whether a >> object is faked or valid. >ES6 WeakSet provides you O(1) object check and don't cause memory leak.
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss