Skip to content

Instantly share code, notes, and snippets.

@AndrewBuntsev
Last active May 29, 2019 20:43
Show Gist options
  • Save AndrewBuntsev/5b12dc05218028e34677c855b6544bec to your computer and use it in GitHub Desktop.
Save AndrewBuntsev/5b12dc05218028e34677c855b6544bec to your computer and use it in GitHub Desktop.
Browser Task & Microtasks
// 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