Last active
August 29, 2015 14:04
-
-
Save zeusdeux/4e78ec74ca11b1ff236c to your computer and use it in GitHub Desktop.
Event loop peculiarities
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
(function(){ | |
var dudeEvent = new CustomEvent('dude'); | |
var body = document.querySelector('body'); | |
body.addEventListener('dude', function(){ | |
console.log('dude listener'); | |
console.log('alerting') | |
alert('wat'); | |
}); | |
function a(){ | |
body.dispatchEvent(dudeEvent); | |
console.log('still in a'); | |
} | |
a(); | |
function b(){ | |
setTimeout(body.dispatchEvent.bind(body, dudeEvent),0); | |
console.log('still in b'); | |
} | |
b(); | |
})(); | |
//output in chrome/firefox | |
//"dude listener" | |
//"alerting" | |
//"still in a" | |
//"still in b" | |
//"dude listener" | |
//"alerting" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment