2

I tried out event delegation and checked the eventPhase of the event object. Surprisingly, it showed 0 meaning Event.NONE explained as "No event is being processed at this time" as defined on Mozilla's eventPhase description.

This is true in the current Chrome, Safari, and Firefox, while IE 11 actually reported a 3 for Event.BUBBLING_PHASE.

You can try out this jsfiddle if you want, but it is optional.

Is there a reason for it to be 0? Is 0 actually more correct (for a reason), or is 3 actually the correct one?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • 3
    That's an artifact of the "live console" feature of these browsers. When you log a complete object, the logged representation will be updated when you expand it, and by that time the event has been processed and `eventPhase` is `0`. Logging `ev.eventPhase` doesn't have this problem and logs `3` ([updated fiddle](https://jsfiddle.net/u0qu1dm9/5/)). – Frédéric Hamidi Jan 23 '16 at 11:09
  • so I supposed these browsers could have saved a shallow copy of the object for debugging accuracy? Interesting... so it seems that IE 11 actually does that, or that it doesn't clear up the `eventPhase` – nonopolarity Jan 23 '16 at 11:13

1 Answers1

-1

According to https://egghead.io/lessons/javascript-the-event-object,

The currentTarget property changes as the event flows through the different event listeners. And it's also set to null when the event is finished dispatching.

Box
  • 2,432
  • 1
  • 18
  • 20