- // 异步任务 封装
- // 1,定义函数
- // 2,使用核心api(queueMicrotask,MutationObserver,setTimeout)
- function runAsynctask (callback){
- if(typeof queueMicrotask ==="function" ){
- queueMicrotask(callback)
- }else if( typeof MutationObserver ==="function" ){
- const obs = new MutationObserver(callback)
- const divNode =document.createElement('div')
- obs.observe(divNode,{childList:true })
- divNode.innerHTML = 'sss'
- }else{
- setTimeout(callback,0)
- }
- }