Proposal About Private Symbol
Kevin Smith
zenparsing at gmail.com
Sun Dec 21 18:18:31 PST 2014
>
> ```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);
> }
> ```
>
One of the goals of any "object-private state" proposal has to be:
- It should be easy to create private-state-carrying abstractions which are
"safe",
- It should be easy to validate such abstractions as "safe".
I think the code above is a great illustration of how private symbols fail
to satisfy these goals.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141221/7c6c3ed0/attachment.html>
More information about the es-discuss
mailing list