Function.prototype.bind = function(context, ...args) {
let object = {...context};
let symbol = Symbol('target');
object[symbol] = this;
return function(...rest) {
return object[symbol](...args, ...rest);
};
};
function bind (cssSelectors, events, callback) {
events = events.split(',');
let elements = document.querySelectorAll(cssSelectors);
elements.forEach(element => {
events.forEach(event => {
element.addEventListener(event, callback)
})
})
}
bind('li > a, p a, div button', 'click, keypress', function (e) {
e.preventDefault();
alert(this.innerText);
});