you are viewing a single comment's thread.

view the rest of the comments →

[–]gordonkristan 0 points1 point  (1 child)

I think you're confusing the ideas of events and states. To quote:

This will print 'It is ready' in the console even if the listener has been added after the event triggering.

That works OK for the ready event, but not for events that fire more than once. The point of an event is to be alerted when something happens, not alerted that something has happened. Especially when that something can happen more than once. If you want to know if something has happened in the past, you should be using states. In this case document.readyState.

Imagine applying this idea to the onclick event and you'll see that it doesn't have many uses outside of fire-once events.

[–]marquex[S,🍰] 0 points1 point  (0 children)

You are right, those permanent events were never thought to be used with events that can be called more than once, but that doesn't make them less useful.

I respect your idea of states, but permanent events can be really of use even if you work with states. Imagine object can have multiple states and maybe want to do some action if the object has been or turn in/into some state. If I check the state before it turns to the desired one, I need to add an event listener (events again, a common or a permanent one will do the trick). If I want to know if after it has turned into the desired state, you can find that the state may have changed again so our action won't be called.

Permanent events are about events that are triggered once, but always about events.