For the following code, I wonder why Object.getPrototypeOf(person)
works, but person.getPrototypeOf(person)
won't work? I thought the rule is: if the object doesn't have such property or method, it will go up the prototype chain to try and get it, and call it on this
(such as Animal.getName.call(this)
where this
is the context of the woofie
object). So in that case, person.getPrototypeOf(person)
should become Object.getPrototypeOf.call(person, person)
and should work too?
function Person(name) {
this.name = name;
}
var person = new Person("Ang Lee")
console.log("the prototype of person is", Object.getPrototypeOf(person));
Update: for the answers that say getPrototypeOf
is a static method, does that mean:
function Person(name) {
this.name = name;
this.foo = function() { ... }
}
Person.bar = function() { ... }
that foo
is "in the chain", and callable by any inherited objects, while bar
is not, and bar
is like getPrototypeOf
, which is a static method?