jQuery学习-事件之绑定事件(六)

在jQuery中,为了屏蔽event对象在各浏览器中的差异性,它使用了自定的Event对象,如下:
 1 jQuery.Event = function( src, props ) {
 2     // Allow instantiation without the 'new' keyword
 3     //instanceof 用于判断一个变量是否某个对象的实例
 4     if ( !(this instanceof jQuery.Event) ) {
 5         return new jQuery.Event( src, props );
 6     }
 7 
 8     // Event object
 9     if ( src && src.type ) {
10         /*
11          如果是event对象
12          * */
13         this.originalEvent = src;//将原生的event对象存于Event中
14         this.type = src.type;//事件类型
15 
16         // Events bubbling up the document may have been marked as prevented
17         // by a handler lower down the tree; reflect the correct value.
18         /*
19          修正isDefaultPrevented方法
20          * */
21         this.isDefaultPrevented = src.defaultPrevented ||
22                 src.defaultPrevented === undefined &&
23                 // Support: IE < 9, Android < 4.0
24                 src.returnValue === false ?
25             returnTrue :
26             returnFalse;
27 
28     // Event type
29     } else {
30         //如果event是事件名称
31         this.type = src;
32     }
33 
34     // Put explicitly provided properties onto the event object
35     //赋值自定义属性
36     if ( props ) {
37         jQuery.extend( this, props );
38     }
39 
40     // Create a timestamp if incoming event doesn't have one
41     this.timeStamp = src && src.timeStamp || jQuery.now();//时间戳
42 
43     // Mark it as fixed
44     this[ jQuery.expando ] = true;//标识event已被处理过
45 };

这个对象不复杂,对吧!

原文地址:https://www.cnblogs.com/urols-jiang/p/4339593.html