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

Go To StackoverFlow.com


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

2012-04-04 18:16
by P K
What browser are you using - Pointy 2012-04-04 18:18
Chrome......... - P K 2012-04-04 18:18
Well the thing is, DOM elements aren't really JavaScript; they're host elements that mimic JavaScript object behaviors. Firefox, for example, will give very different results - Pointy 2012-04-04 18:22
The premise of your question is actually incorrect: HTMLDivElement.constructor.prototype !== HTMLDivElemen - Matthew Caruana Galizia 2012-04-04 18:22
Thanks Pointy, actually firefox shows xpconnect for HTMLDIVElement and HTMLElement both. So i am unable to differentiate the results between chrome and firefox. element.proto.toString(); [xpconnect wrapped native prototype] element.proto.proto.toString(); [xpconnect wrapped native prototype - P K 2012-04-04 18:27
@Praveen HTMLDivElement.constructor.prototype.constructor.prototype == HTMLDivElement.constructor.prototype in both browser - kirilloid 2012-04-04 18:33
yes that's true, constructor.prototype.constructor.prototype is same but how u r relating it with my question - P K 2012-04-04 18:35
@Pointy, can you help me further by any link - P K 2012-04-04 18:37
From experiment with chrome and firefox i found that constructor.prototype is not good way to proceed in prototype chain. proto should be used for that purpose and dom model doesn't follow prototype object definition from ES5 standard - P K 2012-04-04 19:16


Chrome console shows me:

HTMLDivElement.constructor.prototype == HTMLDivElement


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

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

2012-04-04 18:22
by kirilloid
a = Object.getPrototypeOf(element) HTMLDivElement, b = Object.getPrototypeOf(a) HTMLElement, a.constructor.prototype == b.constructor.prototype fals - P K 2012-04-04 18:31
No it's not same i just checked in chrome, shows fals - P K 2012-04-04 18:32
Maybe, you're using some JS library, which modifies Element prototypes - kirilloid 2012-04-04 18:34
No i am not using any library... - P K 2012-04-04 18:36
$('#adzerk3')[0] == HTMLDivElement. This is how they're relate - kirilloid 2012-04-04 18:40


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).

2012-04-04 18:27
by ZER0
Thanks, I was messing around wondering why, seems to be an illegal constructor. Thank - rahpuser 2016-03-22 17:20