[Native] micro and macro task tasks

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>//  事件驱动型语言// console.log("a");  // document.addEventListener("nihao",nihaoHandler);//侦听事件// var evt=new Event("nihao");   //新建事件// document.dispatchEvent(evt);// console.log("b");//     the console.log ( "C");//function nihaoHandler (E) {// event execution//
            

            
            
            
            
            

            
            
            } 
// Event timeliness, the print result is ACB   

// code to run the following result is ABC, this event is not executed in time 

            // the console.log ( "A"); 
            // the setTimeout (timeHandler, 0); 
            // the console.log ( "B"); 

            // function timeHandler () { 
            //      the console.log ( "C"); 
            // } 


            // the console.log ( "A"); 
            // . Promise.resolve () the then (function () { 
            //      console.log ( "B"); 
            // }) // asynchronous 
            // console.log ( "C"); 

// 01 is a print order, a micro and a macro task task 
            console.log ( "A"); // 01 
            the setTimeout (timeHandler, 0 );
            Promise.resolve () the then (. Function () { 
                the console.log ( "C"); // 03 
            }); 
            the console.log ( "D"); // 02 
            function timeHandler () { 
                the console.log ( "B "); // 04 
            } // run results: a, D, C, B 


            // micro and macro tasks task 
            // macrotask setTimeOut, when placed under a front setInterval when the trigger tasks column 
            // micro task when Promise when triggered, the last column on the current task faces execution 


// ainjmbedcklfgh 

        //     console.log ( "a"); 
        //     document.addEventListener ( "ab", abHandler);
        //    //1
        //    setTimeout(function(){
        //         console.log("b");
        //         document.dispatchEvent(new Event("ab"));
        //         Promise.resolve().then(function(){
        //             console.log("c");
        //             //4
        //             setTimeout(timeHanlder,0)
        //         });
        //         console.log("d");
        //    },0);
        //    new Promise(function(res,rej){
        //        console.log("i");//这个是同步执行的
        //        //2
        //        setTimeout(function(){
        //            console.log("k");
        //        },0)
        //        res();
        //    }).then(function(){
        //        console.log("j");
        //        //3
        //        setTimeout(function(){
        //            console.log("l")
        //        },0);
        //        Promise.resolve().then(function(){
        //            console.log("m");
        //        })
        //    });
        //    console.log("n");
        //    function abHandler(e){
        //        console.log("e");
        //    }
        //    timeHanlder function () { 
        //         the console.log ( "F"); 
        //         new new Promise (function (reslove, Reject) { 
        //             the console.log ( "G"); // execute the same synchronization 
        //              reslove () 
        / /         .}) the then (function () { 
        //              the console.log ( "H"); 
        //         }) 
        //     } 




        //     var. 3 = A; 
        //     Promise.resolve () the then (function (.) { 
        / /          the console.log (A + B); 
        //          // this script tag list of tasks completed 
        //          var div = document.querySelector ( "div"); 
        //          the console.log (div); 
        //     }); 
        //    var b=4;

        //    var div=document.createElement("div");
        //    document.body.appendChild(div);
    </script>
    <!-- <div></div> -->

</body>
</html>

 

Guess you like

Origin www.cnblogs.com/yuanjili666/p/11464701.html