Using Custom Events as a web component API

Yonatan Kra
InstructorYonatan Kra

Share this video with your friends

Send Tweet

In this lesson you will learn how to use custom events to expose internal events from withing a web component.

Denys
Denys
~ 5 years ago

May I ask why it is you define ids but then use querySelector('#id')? Isn't it more efficient to use getElementById('id')?

Denys
Denys
~ 5 years ago

Overall a well thought out tutorial a well presented. Thank You

Yonatan Kra
Yonatan Krainstructor
~ 5 years ago

Thanks for the feedback Denys :) Regarding your question:

May I ask why it is you define ids but then use querySelector('#id')? Isn't it more efficient to use getElementById('id')? Performance was not the point of the lesson and querySelector was what I came up with at the time. When writing your app you should consider optimizing when needed. In this case, I query for 3 elements only once so it would be microoptimization to take this into account. If you are optimizing in a for loop, then you'd might have performance implications. See this jsperf for reference: https://jsperf.com/queryselectorall-vs-getelementbyid/35 Cheers!

Denys
Denys
~ 5 years ago

I really appreciate your response and for taking time out to find and the link , the results of which I found quite interesting.

Thank you

Denys