function addDelegate(el, selector, type, handler) {
  var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;

  if (capture !== undefined && !isBoolean(capture) && supportsPassive) {
    capture = { passive: true };
  }
  var handlerWrap = function handlerWrap(e) {
    var targetElsArr = findParents(e.target || e.srcElement, el, true);
    var targetElArr = query(selector, el, true);
    var retEl = void 0;
    if (targetElArr.find) {
      retEl = targetElArr.find(function (seEl) {
        return targetElsArr.find(function (tgEl) {
          return seEl === tgEl;
        });
      });
    } else {
      // Fixed IE11 Array.find not defined bug
      targetElArr.forEach(function (seEl) {
        return !retEl && targetElsArr.forEach(function (tgEl) {
          if (!retEl && seEl === tgEl) {
            retEl = tgEl;
          }
        });
      });
    }
    retEl && handler.apply(retEl, arguments);
  };
  /* 将包装后的方法记录到缓存中 */
  addEventCache(el, type + '_delegate_' + selector, handler, handlerWrap);
  el.addEventListener(type, handlerWrap, capture);
}
function addDelegate(el, selector, type, handler) {
  var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;

  if (capture !== undefined && !isBoolean(capture) && supportsPassive) {
    capture = { passive: true };
  }
  var handlerWrap = function handlerWrap(e) {
    var targetElsArr = findParents(e.target || e.srcElement, el, true);
    var targetElArr = query(selector, el, true);
    var retEl = void 0;
    if (targetElArr.find) {
      retEl = targetElArr.find(function (seEl) {
        return targetElsArr.find(function (tgEl) {
          return seEl === tgEl;
        });
      });
    } else {
      
      targetElArr.forEach(function (seEl) {
        return !retEl && targetElsArr.forEach(function (tgEl) {
          if (!retEl && seEl === tgEl) {
            retEl = tgEl;
          }
        });
      });
    }
    retEl && handler.apply(retEl, arguments);
  };
  
  addEventCache(el, type + '_delegate_' + selector, handler, handlerWrap);
  el.addEventListener(type, handlerWrap, capture);
}
function addDelegate ( el , selector , type , handler ) { var capture = arguments . length > 4 && arguments [ 4 ] !== undefined ? arguments [ 4 ] : false ; if ( capture !== undefined && ! isBoolean ( capture ) && supportsPassive ) { capture = { passive : true } ; } var handlerWrap = function handlerWrap ( e ) { var targetElsArr = findParents ( e . target || e . srcElement , el , true ) ; var targetElArr = query ( selector , el , true ) ; var retEl = void 0 ; if ( targetElArr . find ) { retEl = targetElArr . find ( function ( seEl ) { return targetElsArr . find ( function ( tgEl ) { return seEl === tgEl ; } ) ; } ) ; } else { // Fixed IE11 Array.find not defined bug targetElArr . forEach ( function ( seEl ) { return ! retEl && targetElsArr . forEach ( function ( tgEl ) { if ( ! retEl && seEl === tgEl ) { retEl = tgEl ; } } ) ; } ) ; } retEl && handler . apply ( retEl , arguments ) ; } ; /* 将包装后的方法记录到缓存中 */ addEventCache ( el , type + '_delegate_' + selector , handler , handlerWrap ) ; el . addEventListener ( type , handlerWrap , capture ) ; }
为HTML元素添加事件代理
@param {HTMLElement} el 目标元素
@param {String} selector 要被代理的元素
@param {String} type 事件名称
@param {Function} handler 处理函数
@param {Boolean} capture 是否在捕获阶段监听
为HTML元素添加事件代理