27
loading...
This website collects cookies to deliver better user experience
const clickHandler = function (e, color) {
e.target.style.backgroundColor = color;
}
buttonOne.addEventListener('click',clickHandler(e, 'red') )
const clickHandler = function (e, color) {
e.target.style.backgroundColor = color;
}
buttonOne.addEventListener('click', function(e) {
clickHandler(e, 'red')
} )
const clickHandler = function (e) {
e.target.style.backgroundColor = this;
}
buttonOne.addEventListener('click', clickHandler.bind('red'))
This hack won't work if the handler function is an arrow function (remember what 'this' means in arrow functions).
const clickHandler = function (e) {
e.target.style.backgroundColor = this[0];
e.target.style.color = this[1]
}
buttonOne.addEventListener('click', clickHandler.bind(['red', 'white']))