function delegate(parentSelectors, eventName, childSelectors, data, handler) { function each(arrlike, cb) { [].forEach.call(arrlike, cb) } var parents = document.querySelectorAll(parentSelectors) each(parents, function (parent) { // each(childs, function (child) { // child.addEventListener(type, handler, false) // }) parents.addEventListener(type, function (e) { var childs = parent.querySelectorAll(childSelectors) var target = e.target || e.srcElement // target 本身为代理节点 // 或者 target 为代理节点子节点 if ([].includes.call(childs, target) || childs.contains(target)) { // handler.call(target, e) } }, false) }) }
功能暂未实现