Created
June 27, 2017 21:04
-
-
Save jmlavoier/3ea5f4e5b7c997d58db202b0d2e065f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const content = document.querySelector('.content') | |
const colors = ['red', 'blue', 'yellow', 'green', 'black']; | |
let index = 0; | |
// Sintaxe ES6 | |
const eventDelegate = (tagName, callback) => event => { | |
if (event.target && event.target.tagName === tagName) { | |
return callback(event); | |
} | |
} | |
const changeColor = function (event) { | |
event.target.style.color = colors[index]; | |
index = index < 4 ? index + 1 : 0; | |
} | |
content.onclick = eventDelegate('P', changeColor); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment