I have the following personal perceptions.
- pubsub pattern: DOM independent
- In both cases, the role of "registering and executing the process triggered by the trigger" does not change.
Is this recognition correct in the first place?
If not, what is the difference between the two?
Please teach me.
Custom events are a feature of the DOM, but the pubsub pattern is, as the name implies, a type of pattern that cannot be simply contrasted. You can think of custom events as one of the implementations of the pubsub pattern.
On top of that, if I dare to mention two features,
If you want to use features such as Bubbling / Capturing that propagate events hierarchically, DOM custom events are suitable. This is a feature not found in the pubsub pattern itself.
If you also want to receive the history of messages notified before Listen / Subscribe, you'll have to implement your own pubsub pattern instead of a custom event.