event.js为jQuery.fn增加了如下接口:
jQuery.fn.extend({ on: function( types, selector, data, fn, /* INTERNAL */ one ){}, one: function( types, selector, data, fn ){}, off: function( types, selector, fn ){}, bind: function( types, data, fn ){}, unbind: function( types, fn ){}, live: function( types, data, fn ){}, die: function( types, fn ){}, delegate: function( selector, types, data, fn ){}, undelegate: function( selector, types, fn ){}, trigger: function( type, data ){}, triggerHandler: function( type, data ){}, toggle: function( fn ){}, hover: function( fnOver, fnOut ){} });
为实现这些接口,使用的对象和数据结构有:
jQuery.event = { add: function( elem, types, handler, data, selector ){}, global: {}, remove: function( elem, types, handler, selector, mappedTypes ){}, customEvent: {}, trigger: function( event, data, elem, onlyHandlers ){}, dispatch: function( event ){}, props: "attrChange ... which", fixHooks: {}, keyHooks: {}, mouseHooks: {}, fix: function( event ){}, special: {}, simulate: function( type, elem, event, bubble ){} };
jQuery.Event = function(){};
jQuery._data = function(){};
核心套路为:
jQuery.event = { add: function(){}, dispatch: function() {} };
为了处理特殊事件和兼容性考虑,引入的特殊数据结构有:
jQuery.event.special = {};
special主要在以下代码流程中起作用:
jQuery.event = { add: function(){}, };
总结: