How Object.getPrototypeOf(obj) works?
As per definition Object.getPrototypeOf(obj) should return prototype property of an Object or in another way it is same as obj.constructor.prototype.
Objects created with new use the value of the prototype property of their constructor function as their prototype.
Lets take an example:
>element = document.getElementById("test")
>a = Object.getPrototypeOf(element)
HTMLDivElement
Let's say HTMLDivElement is the prototype of element.
>a.constructor.prototype
HTMLDivElement
so a.constructor.prototype is HTMLDivElement so Object.getPrototypeOf(a) should return HTMLDivElement but it returns HTMLElement. I am totally confused with definition of getPrototypeOf().
>b = Object.getPrototypeOf(a)
HTMLElement ----> why? a.constructor.prototype is HTMLDivElement
Actually it's returning proto property of prototype, isn't it wrong as per definition of getPrototypeOf()?
>a.constructor.prototype.__proto__
HTMLElement