There are many loopholes in this way of writing, because many situations are not considered. For example, IE's event binding is not considered. For example, multiple events do not consider multiple callbacks.
But. After all, the purpose is to tell you your thoughts, not to reinvent the wheel for you.
The implementation of JQuery probably follows the same logic. You can use this method to encapsulate your own library.
Give you a simple example. If you want to use the on method in native JS, you can write it like this:
There are many loopholes in this way of writing, because many situations are not considered. For example, IE's event binding is not considered. For example, multiple events do not consider multiple callbacks.
But. After all, the purpose is to tell you your thoughts, not to reinvent the wheel for you.
The implementation of JQuery probably follows the same logic. You can use this method to encapsulate your own library.
addEventListener