New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

Projects
None yet
5 participants
@lazd

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

This comment has been minimized.

Show comment
Hide comment
@addyosmani

addyosmani Mar 4, 2015

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?

Member

addyosmani commented Mar 4, 2015

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

This comment has been minimized.

Show comment
Hide comment
@lazd

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

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

This comment has been minimized.

Show comment
Hide comment
@garlicnation

garlicnation Mar 9, 2015

Contributor

Documented in FAQs section of README.md.

Contributor

garlicnation commented Mar 9, 2015

Documented in FAQs section of README.md.

@zanona

This comment has been minimized.

Show comment
Hide comment
@zanona

zanona 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?

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

This comment has been minimized.

Show comment
Hide comment
@dartess

dartess Jan 15, 2018

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

dartess commented Jan 15, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment