Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

instance.constructor property is wrong in Safari and IE #215

Closed
lazd opened this issue Feb 24, 2015 · 5 comments
Closed

instance.constructor property is wrong in Safari and IE #215

lazd opened this issue Feb 24, 2015 · 5 comments

Comments

@lazd
Copy link

lazd commented Feb 24, 2015

I saw today that custom elements created with webcomponents.js have a constructor property of HTMLUnknownElementConstructor in Safari and HTMLUnknownElement in IE.

Is this an unavoidable side-effect of the polyfill? I would expect it to be the same constructor returned by document.registerElement.

Test code:

var ATag = document.registerElement('a-tag', { prototype: HTMLElement });
var aTag = new ATag();
aTag instanceof ATag // true in Safari, Chrome, etc
aTag.constructor === ATag // false in Safari and IE, but true in Firefox, Chrome
@addyosmani
Copy link
Member

IE doesn't work particularly well with unknown element types and marks them as HTMLUnknownElement, whilst afaik, WebKit aliases HTMLUnknownElement to HTMLUnknownElementConstructor (unavoidable to the best of my knowledge). Is there a specific use-case where the difference in polyfilled constructor behavior is causing breakage?

@lazd
Copy link
Author

lazd commented Mar 4, 2015

I was attempting to infer the constructor of an instance using the instance.constructor property and realized the code failed on Safari.

Sounds like this is expected and unavoidable, let's document it somewhere.

@garlicnation
Copy link
Contributor

Documented in FAQs section of README.md.

@zanona
Copy link

zanona commented Jun 8, 2016

Is there any recommended way currently to get the constructor class of a CustomElement?
it seems the element.__proto__.__proto__.constructor will return the extended class instead? whereas element.__proto__ returns a function instead of the class itself?

@dartess
Copy link

dartess commented Jan 15, 2018

Is this relevant for v1? I could not reproduce the problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants