If I have an object:
A = {a:true}
Why do I have to use:
Object.keys(A)
and not:
A.keys()
If keys is a method of Object, and everything inherits from Object, shouldn’t A be able to call keys?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Object.keysis a so-to-say “static” method attached strictly to theObjectfunction, not to its instances.For it to be inherited, it would need to be defined as
Object.prototype.keys.You can certainly add it yourself if you so desire:
Just note, as Rocket mentioned in the comments, “own” properties take precedence over
prototypeproperties: