Last active
May 29, 2019 20:43
-
-
Save AndrewBuntsev/5b12dc05218028e34677c855b6544bec to your computer and use it in GitHub Desktop.
Browser Task & Microtasks
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
// Let's get hold of those elements | |
var outer = document.querySelector('.outer'); | |
var inner = document.querySelector('.inner'); | |
// Let's listen for attribute changes on the | |
// outer element | |
new MutationObserver(function() { | |
console.log('mutate'); | |
}).observe(outer, { | |
attributes: true | |
}); | |
// Here's a click listener… | |
function onClick() { | |
console.log('click'); | |
setTimeout(function() { | |
console.log('timeout'); | |
}, 0); | |
Promise.resolve().then(function() { | |
console.log('promise'); | |
}); | |
outer.setAttribute('data-random', Math.random()); | |
} | |
// …which we'll attach to both elements | |
inner.addEventListener('click', onClick); | |
outer.addEventListener('click', onClick); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment