02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Q:Why Event Order is this way?

Student Question: Why are the events in this order?

Video Transcript

00:00Adam asks, why is the touch happening before,
00:04why is it happening before the click?
00:07And the answer to that, it's kind of hard to see it
00:09when we're looking, it was hard for me as well.
00:10It's hard to see it when we're looking at this.
00:11I could put here the click first and the touch second,
00:13but still it's happening first.
00:15Why is that?
00:16The reason is because the touch event is dependent
00:19on when the touch is triggered.
00:21The touch is triggered only after,
00:23if we look in the animal, the touch event is only triggered
00:25after the touch function is called,
00:27which is only called after this function is called.
00:30This function is called only
00:32when this add event listener is called.
00:34We have to take a lot of steps back.
00:36So we see that we had an add event listener in the animal,
00:39which was the first add event listener
00:40that had a click in it
00:41because it happened in the constructor.
00:44Later on, we added another event listener
00:46and this was second.
00:47So no matter if I put this up here in the line,
00:49it really doesn't matter.
00:50The reason is, is this happened second.
00:53This is added into the cue second.
00:54So imagine that it's an array, it is an array.
00:56The first array element, the first listener was internal.
01:00The second listener was external.
01:02So now when I'm listening to something else,
01:04that something else has no relevance
01:06to the order of this one.
01:07And this order really technically in this scenario
01:10defined when this will happen.
01:12Okay, so now that I answered
01:14and I think I answered better this time around,
01:16let me go back to Adam
01:17and just make sure that that answer was good.
01:21Okay, great.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!