macro-renzhansheng

基础插件应用

const path = require(\'path\');

const fs = require(\'fs\');

const url = require(\'url\');

const http = require(\'http\');

const mime = require(\'mime\');

=========================

创建服务器

const app = http.createServer();

============================

app.on(\'request\', (req, res) => {

//res.end(\'hello\');

console.log(url.parse(req.url));

let { pathname } = url.parse(req.url);

if (pathname === \'/\') {

pathname = \'/index.html\';

    }

let absPath = path.join(__dirname, \'public\', pathname);

console.log(absPath);

let type = mime.getType(absPath);

fs.readFile(absPath, \'utf8\', (err, data) => {

//不存在当前页面

if (err !== null) {

res.writeHead(404, {

\'content-type\': \'text/html;charset=utf8\'

            });

res.end(\'你访问的页面不存在\');

        }

res.writeHead(200, {

\'content-type\': type

        });

res.end(data);

    });

});

app.listen(9999);

浏览器事件环

浏览器事件环: 全局执行环境(执行上下文)

    js单线程(主线程)——程序的执行路径

    同步有限,然后异步。

    异步线程:放置缓冲区【异步任务队列】

        setTimeout\setInterval              宏任务

        onclick:事件回调

        promise                             微任务

        ajax

    微任务 > 宏任务

    script宏任务先执行,之后的执行过程:先清空微任务,再执行宏任务。

==================================浏览器常用的宏任务微任务====================================

宏任务:JS渲染,ui渲染,定时器:setTimeout\setInterval\setImmdiate ,node中的I\O操作

微任务:promise[不同版本实现,特例:宏任务],process.nextTick, Object.observe , MutationObserver

Vue.nextTick(function(){}) ——异步的微任务

    支持promise,采用promise实现;

    不支持,使用MutationObserver

    不支持,使用setImmediate

    不支持,使用setTimeout




待深入部分:

模块化
事件环

分类:

技术点:

相关文章:

  • 2021-08-01
  • 2021-04-23
  • 2022-12-23
  • 2021-05-05
  • 2022-01-01
  • 2021-04-29
  • 2021-05-18
猜你喜欢
  • 2021-08-05
  • 2022-12-23
  • 2021-12-03
  • 2021-04-28
相关资源
相似解决方案