Robert
Robert

Reputation: 10390

JavaScript get prototype of object

I have:

var person = {
    kind: 'person'
};

// create new object specifying the prototype as person
var zack = Object.create( person );

console.log( Object.getPrototypeOf(zack) );

Output: Object {kind: "person"}

Why does it not output person?

Upvotes: 0

Views: 70

Answers (1)

TaoPR
TaoPR

Reputation: 6052

When you get the prototype of an object by Object.getPrototypeOf(zack), it returns you the prototype object which is obviously your person object:

enter image description here

Your prototype object potentially has properties you defined for it (kind: "person"). Both person object you defined and prototype object returned by the function are equivalent.

Try checking the equality, you'll realize both are equal.

alert(person === Object.getPrototypeOf(zack)); // true

Upvotes: 1

Related Questions