Why #JavaScript doesn't expose a static Object method which returns the number of the object own enumerable properties?

I find `Object.keys(obj).length` a bit clunky.

Follow

@abozhilov I must admit, I don't understand why static methods in are that way at all. Why Object.keys(obj) and not obj.keys() as one would have in or ?

@jmft Basically because it would break the web. There were popular libraries which extended `Object.prototype` and if those method were introduced through `Object.prototype` a lot of websites would stop working correctly.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.