'use strict';

/**
 * 触发一个自定义事件
 * @param {*} eName  自定义事件名称
 * @param {*} detail 自定义事件参数
 * @param {*} target 自定义事件元素，默认windows
 *
 * const logEventDetail = e => console.log(e.detail);
 *
 * window.addEventListener('hello', logEventDetail);
 * dispatchCustomEvent('hello', '哈啰'); // => 哈啰
 *
 * window.removeEventListener('hello', logEventDetail);
 * dispatchCustomEvent('hello', '哈啰'); // => 无打印
 */
function dispatchCustomEvent(eName, detail, target) {
  if (target === undefined) target = window;
  return target.dispatchEvent(new CustomEvent(eName, {
    detail: detail
  }));
}

module.exports = dispatchCustomEvent;
