Skip to content
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

Feature request: testing whether a custom element extends a certain type #380

Closed
jganetsk opened this issue Dec 17, 2013 · 3 comments
Closed
Assignees

Comments

@jganetsk
Copy link

I would like to be able to call element.isSubClassOf('abstract-custom-element-type'). Looking at the tag name doesn't tell me this information. I'm not aware of how else to do this at teh moment.

@sorvell
Copy link
Contributor

sorvell commented Dec 18, 2013

In general, you should use 'instanceof' to do this. There's a number of
ways to get the constructor for a custom element:

  1. you can name it in your declaration and then it becomes a global:

  2. you can get the constructor from an instance, e.g.

    XFoo =
    Object.getPrototypeOf(document.createElement('x-foo')).constructor;

Then if xbar descends from XFoo, you would do:

assert(xbar instanceof XFoo)

On Tue, Dec 17, 2013 at 3:04 PM, jganetsk notifications@github.com wrote:

I would like to be able to call
element.isSubClassOf('abstract-custom-element-type'). Looking at the tag
name doesn't tell me this information. I'm not aware of how else to do this
at teh moment.


Reply to this email directly or view it on GitHubhttps://github.com//issues/380
.

@jganetsk
Copy link
Author

I could try to argue that this would be breaking the abstraction and peering into implementation details.

A better argument is a utility method would just come in handy.

@sorvell sorvell assigned sorvell and sjmiles and unassigned sorvell Aug 11, 2014
@sorvell sorvell added p1 and removed p3 labels Aug 20, 2014
@sorvell sorvell assigned sorvell and unassigned sjmiles Aug 20, 2014
@sorvell
Copy link
Contributor

sorvell commented Aug 20, 2014

We can make use of this:

Polymer.getRegisteredPrototype('core-item').constructor

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

No branches or pull requests

3 participants