Proposal About Private Symbol

Domenic Denicola d at
Sun Dec 21 09:37:48 PST 2014

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-bounces at] On Behalf Of Gary Guo
Sent: Sunday, December 21, 2014 07:26
To: es-discuss at
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.

var constructor=function(){
    'use strict';
    var allObjects=new WeakSet();
    var privateSymbol=Symbol('private', true);
    var ret=function(){
        if(this===undefined)throw Error('Invalid Construction');
        if(!allObject.has(this))throw Error('Invalid Call');
        this[privateSymbol]=sth; // Now this can be called safely, no more worry about leak to Proxy

On Sun, 21 Dec 2014 12:30:46 +0100, Michal Wadas <michalwadas at<mailto:michalwadas at>> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list