Object.keys(): Why no inherited properties?

Brendan Eich brendan at mozilla.com
Wed Sep 7 09:53:43 PDT 2011


On Sep 7, 2011, at 9:29 AM, Dmitry Soshnikov wrote:

> On 07.09.2011 19:33, Felipe Gasper wrote:
>> Why does Object.keys() not allow, as an option, iterating through inherited properties?
>> 
> 
> Because it's the same version that is from Prototype.js. I guess it was ported "as is" for compatibility with the library. But IMO, yes, native implementation could provide at least an option for this case (if needed).

If you mean that an ES5-conforming implementation could add an optional boolean parameter to Object.keys, to get inherited enumerable properties too, then please, no: that is against the NOTE in Clause 15 (quoting from ES5.1):

NOTE Implementations that add additional capabilities to the set of built-in functions are encouraged to do so by adding new functions rather than adding new parameters to existing functions.

I think we should make this a normative restriction in ES6.

/be



More information about the es-discuss mailing list