<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>browser</title>
</head>
<body>
<div id="app"></div>
<script>
let channel = new MessageChannel();
channel.port1.postMessage('i love you');
channel.port2.onmessage = function (e) {
console.log(e.data);
}
let observer = new MutationObserver(function(){
console.log('节点已更新');
console.log(app.children.length)
});
observer.observe(document.getElementById('app'),{
childList:true
});
for(let i=0;i<20;i++){
app.appendChild(document.createElement('p'));
}
for(let i=0;i<20;i++){
app.appendChild(document.createElement('span'));
}
setTimeout(function(){
console.log('timeout');
},20);
Promise.resolve().then(function(){
console.log('promise');
});
</script>
</body>
</html>