Understanding Dean Edwards' addevent JavaScript

后端 未结 1 1101
我寻月下人不归
我寻月下人不归 2021-01-14 16:44

I need help understanding this piece of code. What is the point of handler.guid? Why is there a need for a hash table?

What is the point of:

1条回答
  •  借酒劲吻你
    2021-01-14 17:10

    The guid is used to give each event a unique index, while the hash table is used to implement a dynamic dispatch table. this.$$handleEvent refers to the element in the handler mapping table.

    A callback system works by storing event handlers in an array. When the underlying event is detected the dispatch system loops through the array calling the callback functions in turn.

    The jQuery Event object uses a similar structure.

    References

    • A Few Words on GUIDs
    • When Should I Use a Dispatch Table
    • Delegating All of the Things With Ruby Forwardable - Words and Code
    • The Gang of Four is wrong and you don't understand delegation — Saturn Flyer
    • GUIDs and UUIDs
    • RFC 4122: A Universally Unique IDentifier (UUID) URN Namespace

    0 讨论(0)
提交回复
热议问题