Created
October 21, 2017 17:59
-
-
Save prof3ssorSt3v3/ee2ff700079760d8f7ffc2a5bc249009 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>handleEvent method</title> | |
<meta name="viewport" content="width=device-width"> | |
<!-- --> | |
<style> | |
</style> | |
</head> | |
<body> | |
<h1>Built-In EventListener handleEvent method</h1> | |
<button id="btn">Click the Button</button> | |
<script> | |
let obj = { | |
init: function (){ | |
document.querySelector('#btn').addEventListener('click', this); | |
document.querySelector('#btn').addEventListener('focus', this); | |
document.querySelector('#btn').addEventListener('blur', this); | |
}, | |
handleEvent: function(ev){ | |
switch(ev.type){ | |
case 'click': | |
this.something(ev); | |
break; | |
case 'focus': | |
this.something(ev); | |
break; | |
case 'blur': | |
this.something(ev); | |
break; | |
case 'explode': | |
break; | |
} | |
}, | |
something: function (ev){ | |
//gets called by click event list | |
console.log('btn was', ev.type, '-ed.'); | |
} | |
} | |
//get things started | |
obj.init(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment