- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <script>
- console.log(1);
- console.log(2);
- console.log(3);
- </script>
- </body>
- </html>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <script>
- console.log(1);
- setTimeout(function(){
- console.log(2);
- },1000)
- console.log(3);
- </script>
- </body>
- </html>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <script>
- console.log(1);
- setTimeout(function(){
- console.log(4);
- },0)
- console.log(3);
- </script>
- </body>
- </html>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <script>
- console.log(1);
- setTimeout(function(){
- console.log(2);
- },3000)
- setTimeout(function(){
- console.log(3);
- },1000)
- </script>
- </body>
- </html>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <script>
- console.log('1');
- setTimeout(function () {
- console.log('2');
- new Promise(function(resolve, reject) {
- console.log('promise-start2');
- resolve();
- }).then(function() {
- console.log('promise-end2');
- });
- },0);
- new Promise(function(resolve, reject) {
- console.log('promise-start');
- resolve();
- }).then(function() {
- console.log('promise-end');
- });
- setTimeout(function () {
- console.log('3');
- },0);
- console.log('4');
- </script>
- </body>
- </html>
还是不懂promise的目的
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <script>
- console.log('1');
- new Promise(function(resolve, reject) {
- console.log('promise-start2');
- // setTimeout(function () {
- // console.log('6');
- // },0);
- resolve();
- }).then(function() {
- setTimeout(function () {
- console.log('3');
- },0);
- console.log('promise-end2');
-
- });
-
- console.log('4');
- </script>
- </body>
- </html>