Javascript: why Object.keys(someobject), rather than someobject.keys?

Viewed 1722

I frequently get an array of an objects keys using:

Object.keys(someobject)

I'm comfortable doing this. I understand that Object is the Object constructor function, and keys() is a method of it, and that keys() will return a list of keys on whatever object is given as the first parameter. My question is not how to get the keys of an object - please do not reply with non-answers explaining this.

My question is, why isn't there a more predictable keys() or getKeys() method, or keys instance variable available on Object.prototype, so I can have:

someobject.keys()

or as an instance variable:

someobject.keys

And return the array of keys?

Again, my intention is to understand the design of Javascript, and what purpose the somewhat unintuitive mechanism of fetching keys serves. I don't need help getting keys.

3 Answers
Related