P K
P K

Reputation: 10210

Why HTMLDivElement.constructor.prototype == HTMLDivElement ? it should be prototype object

ECMASCRIPT defines prototype object as prototype property of constructor.

Below is copied from ECMA-262:

4.3.4 constructor function object that creates and initialises objects NOTE The value of a constructor‘s "prototype" property is a prototype object that is used to implement inheritance and shared properties.

Why HTMLDivElement.constructor.prototype == HTMLDivElement ?

if a is a HTMLDivElement object, Object.getPrototypeOf(a) returns HTMLElement while it should return constructor.prototype which is HTMLDivElement.

It's a complete contradict with ECMA standard.

Please help me understanding this concept... Thanks a ton in advance.

enter image description here

Upvotes: 0

Views: 2220

Answers (2)

ZER0
ZER0

Reputation: 25322

HTMLDivElement is defined as interface by w3c (see http://www.w3.org/TR/html5/the-div-element.html#htmldivelement), so its implementation depends and vary by browser's vendor.

In Chrome is not a proper constructor (just try to execute new HTMLDivElement), in Firefox it's not a constructor at all (it's an object).

Upvotes: 1

kirilloid
kirilloid

Reputation: 14304

Chrome console shows me:

HTMLDivElement.constructor.prototype == HTMLDivElement

false

The fact it is displayed in console as HTMLDivElement doesn't mean it is a HTMLDivElement.

Also: HTMLDivElement.constructor.prototype == HTMLElement.constructor.prototype

Upvotes: 3

Related Questions