Two different use cases for privacy?

André Bargull andre.bargull at
Mon Mar 25 01:55:37 PDT 2013

The function for use case #1 seems to be Object.getOwnPropertyKeys() []:

js> Object.keys(Array)
js> Object.getOwnPropertyNames(Array)
js> [for (x of Object.getOwnPropertyKeys(Array)) x]

> 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  <>
> home:
> twitter:
> blog:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list