Private Slots

Claude Pache claude.pache at gmail.com
Mon Jan 14 11:46:50 PST 2013


Le 14 janv. 2013 à 19:29, Kevin Smith <khs4473 at gmail.com> a écrit :

> 
>> 
>> The concept of freezing the "whole object" is the problem.  If you
>> call `freeze` on a DOM object, does the page stop changing?  Of course
>> not -- objects can have hidden state that you, the client of that
>> object, have no access to and thus no way to freeze.  This isn't
>> something new being added here.
> 
> Slots whose existence is guaranteed to be completely hidden from all code that does not possess a "magic key" looks new to me.
> 
> You can argue that the change is justified (that's the kind of argument I'd like to see in fact), but arguing that it "isn't something new" isn't working for me.
> 
> { Kevin }
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

Really, there is nothing new. Try this in your favorite ES5-compliant browser:

d = new Date(2000, 0, 1)
Object.freeze(d)
d // output: Sat Jan 1 2000 ...
d.setFullYear(2001)
d // output: Mon Jan 1 2001 ... Uh? the date was not frozen!

The value of the Date object is stored in some internal "slot", which is not enumerable with Object.getOwnPropertyName or configurable with Object.defineProperty, but only accessed by some ad-hoc API.

Symbols allow you to store protected properties (just like the date of a Date object) in a natural manner, without resorting to some clever hack. And the very definition of "protected" means that you can't access if you haven't the key. It is really the raison d'être of symbols. 

—Claude
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130114/4b7ff4cb/attachment.html>


More information about the es-discuss mailing list