标签: 事件循环

8 个内容

笔记(7)

本文深入解析DOM事件处理、渲染模型、DOM操作、事件循环与性能优化等核心机制,并探讨移动端交互、页面生命周期、脚本加载策略及选择操作的现代实践。同时,展望了Web Components等前沿趋势,强调安全与性能优化,建议开发者持续关注Web平台最新发展。

Elliot Yang·
86 浏览

本文解析了JavaScript中`var`与`let`在循环闭包中的差异,揭示了变量提升、块级作用域和词法环境等核心概念。对比了历史解决方案、现代工程实践以及其他语言的实现,强调使用`let`构建清晰作用域边界的重要性,以避免常见陷阱并提升代码可预测性。

Elliot Yang·
99 浏览

本文深入解析 JavaScript Promise,阐述其作为有限状态机的核心机制、微任务执行原理和链式调用。对比 `all`、`allSettled` 和 `any` 等静态方法,探讨取消模式、内存泄漏规避及性能优化。最后提及 Promise 实现规范和未来演进,强调实践中的最佳策略。

Elliot Yang·
86 浏览

Node.js核心机制包括高精度计时(process.hrtime),异步资源追踪(async_hooks)和上下文管理(AsyncLocalStorage)。文件系统操作需注意同步写入风险。PowerShell假死问题可通过检查事件循环和缓冲机制解决。了解全局对象差异,掌握二进制数据处理技巧,结合性能分析工具和安全措施,能构建高性能Node.js应用。

Elliot Yang·
108 浏览

Node.js同步I/O阻塞主线程,异步I/O利用libuv线程池。流式读取I/O性能最佳,Promise存在内存合并损耗。工程实践中,I/O密集型场景用异步流,CPU密集型用Worker Threads。同步I/O适于启动阶段。需警惕Promise陷阱和内存泄漏,并监控事件循环延迟。

Elliot Yang·
98 浏览

该文探讨Node.js同步/异步文件读取性能差异及阻塞问题。背景:`fs.promises.readFile`比`fs.readFile`慢。问题:同步读取阻塞事件循环,影响并发。方案:避免同步I/O,采用异步方式,如`fs.promises.readFile`,提升服务器并发性能。

Elliot Yang·
141 浏览

本文深入解析了 Promise 的三种状态(pending, fulfilled, rejected)、resolve参数的不同类型处理、then/catch/finally方法,以及静态方法 all, allSettled, race, any 的用法。最后,文章还提供了一个 Promise 的简单实现,并简要提及了 postMessage 相关的异步任务执行顺序问题。

Elliot Yang·
96 浏览

动态(1)

E
Elliot Yang
公开

The queueMicrotask() method, which is exposed on the Window or Worker interface, queues a microtask to be executed at a safe time prior to control returning to the browser's event loop.
First, nextTick queue is checked to get tasks for its execution, once it is exhausted, the microTasks queue is checked. After finishing the tasks in the microtask queue the process of checking nextTick and microTasks queues are repeated until the queues have been emptied.
They have different queues. The nextTick's queue is managed by node and the microtask one is managed by v8.
The nextTick queue is checked first after the current function/script execution, and then the microTask one.

浏览:142点赞:0