Proposal: Reflecting on non-string property names
allen at wirfs-brock.com
Fri Nov 30 16:18:15 PST 2012
1) In ES6 property keys are no longer limited to string values, we now also have keys that are Symbols.
2) Some meta-programming tasks will requires a way to reflectively obtain a list of all public property keys.
3) The existing reflection APIs for property keys (Object.getOwnPropertyNames and Object.keys) only return string values and we don't want to break existing clients of those functions by returning non-string values.
1) Object.getOwnPropertyNames and Object.keys remain unchanged. They only return a string property key values.
2) Reflect.ownKeys(obj) is a new reflection function that returns an iterator. The iterator produces the keys of all public own properties of the object pass as an argument. This includes both string and Symbol key values. A property whose key is a private Symbol is not a public property and its key is not returned by the ownKeys iterator.
3) The [[OwnPropertyKeys]] internal method is defined to return an iterator with the same definition as used for Reflect.ownKeys. (Reflect.ownKeys is implemented as a call to this internal method). [[OwnPropertyKeys]] replaces the like-named internal method in the current spec. draft and also replaces the [[GetOwnPropertyNames]] internal method used in the wiki Proxy proposals.
4) ownKeys is the corresponding Proxy trap. The getOwnPropertyNames trap is removed.
5) Object.keys and Object.getOwnPropertyNames are respecified in terms of [[OwnPropertyKeys]]. They internally drain the iterator and continue to return arrays of strings.
More information about the es-discuss