function bindEvent(elem, type, selector, fn) {
if (fn == null) {
fn = selector;
selector = null;
}
elem.addEventListener(type, function(e) {
var target = e.target;
if (selector) {
//代理
if (target.matches(selector)) {
fn.call(target, e)
}
} {
//非代理
fn.call(target, e)
// fn(e)
}
})
}
var div1 = document.getElementById('div1')
bindEvent(div1, 'click', 'a', function(e) {
console.log(this.innerHtml)
})
var p = document.getElementById('p')
bindEvent(p, 'click', function(e) {
console.log(this.innerHtml)
})