The function for use case #1 seems to be Object.getOwnPropertyKeys()
[15.2.3.15]:
js> Object.keys(Array)
[]
js> Object.getOwnPropertyNames(Array)
["length","name","prototype","isArray","of","from","caller","arguments"]
js> [for (x of Object.getOwnPropertyKeys(Array)) x]
["length","name","prototype","isArray","of",@@create,"from","caller","arguments"]
It seems to me that there are two different use cases for privacy:
Use case 1: Hide some properties from the outside (when listing properties or getting
expansion help from an IDE). Many people use a naming convention here (e.g. a prefixed
underscore). This hiding does not have to be completely safe. There could be methods that
list all property keys, even hidden ones. Hiding is more like a hint ("you don't
normally need to look at this") than actual protection.
Use case 2: Keep data completely safe inside an object.
#1 is very similar to the [[Enumerable]] attribute (if it was used slightly
differently and more consistently). Symbols already almost serve this use case,
because they are hidden from current ways of listing property keys. But you
don't want to hide some of the public symbols such as @@create. Hence, all that
would be needed would be a flag, as a hint for IDEs and functions that list
property keys.
#2 could be handled via WeakMap.
Do I see this correctly?
--
Dr. Axel Rauschmayer
axel at rauschma.de <https://mail.mozilla.org/listinfo/es-discuss>
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss