词表 · 第 4 篇
JavaScript
1. animation
- 译:动画 | JS:随时间改变元素视觉属性的呈现,常配合 requestAnimationFrame
- 例
- Pause the animation on hover. — 鼠标悬停时暂停动画。
- The library handles animation timing for you. — 这个库为你处理动画计时。
- 地道:smooth out the animation(让动画变流畅)
- 短语:CSS animation · requestAnimationFrame · animation frame
2. async
- 译:异步 | JS:async 关键字,声明异步函数并使其返回 Promise
- 例
- Mark the function async to use await. — 把函数标为 async 才能在内部用 await。
- An async function always returns a promise. — async 函数总是返回 promise。
- 地道:async/await sugar(async/await 语法糖)
- 短语:async function · async/await · async arrow function
3. await
- 译:等待 | JS:暂停 async 函数执行直到 Promise 落定
- 例
- Use await to pause until the promise resolves. — 用 await 暂停,直到 promise 完成。
- Await the fetch result before rendering. — 渲染前先 await fetch 的结果。
- 地道:await a promise(等待一个 promise)
- 短语:await expression · top-level await · await + try/catch
4. canvas
- 译:画布 | JS:可用脚本绘图的 HTML 元素及 2D/WebGL API
- 例
- Draw shapes on the canvas via the 2D context. — 通过 2D 上下文在 canvas 上绘图。
- Resize the canvas to fit its container. — 调整 canvas 尺寸以适配容器。
- 地道:paint on a canvas(在画布上绘制)
- 短语:canvas element · 2D context · WebGL canvas
5. closure
- 译:闭包 | JS:函数与其词法作用域中变量的组合,让函数记住定义处的变量
- 例
- A closure remembers variables from where it was defined. — 闭包会记住它定义处的变量。
- Use a closure to hide private state. — 用闭包隐藏私有状态。
- 地道:closing over a variable(捕获某变量形成闭包)
- 短语:closing over · lexical scope · factory closure
6. decode
- 译:解码 | JS:把编码后的字符串/字节还原,如 atob、TextDecoder
- 例
- Decode the base64 string with atob. — 用 atob 解码 base64 字符串。
- TextDecoder decodes UTF-8 bytes into a string. — TextDecoder 把 UTF-8 字节解码成字符串。
- 地道:encode and decode(编解码)
- 短语:atob / TextDecoder · URL decode · JSON parse
7. document
- 译:文档(DOM 树的根节点,window.document)
- 短语:document.querySelector · document.createElement · DOM document
8. element
- 译:元素(DOM 中的一个节点,HTMLElement)
- 短语:DOM element · root element · child element
9. event loop
- 译:事件循环 | JS:调度调用栈、宏任务、微任务队列,使异步回调得以执行的机制
- 短语:task queue · microtask · call stack
10. fetch
- 译:取回 | JS:基于 Promise 的现代网络请求 API
- 例
- Fetch returns a promise that resolves to a Response. — fetch 返回一个 resolve 为 Response 的 promise。
- Use fetch to call the API endpoint. — 用 fetch 调用 API 端点。
- 地道:fetch a resource(获取一个资源)
- 短语:fetch API · fetch + await · Response object
11. frames
- 译:帧;框架 | JS:动画的一帧或页面中的嵌入框架(window.frames、AnimationFrame)
- 例
- Aim for 60 frames per second. — 目标是每秒 60 帧。
- Access nested frames via window.frames. — 通过 window.frames 访问嵌套框架。
- 地道:drop frames(掉帧)
- 短语:animation frame · iframe · frame rate
12. hoisting
- 译:提升 | JS:变量/函数声明在编译阶段被”提升”到作用域顶部的行为
- 例
- Hoisting moves declarations to the top of their scope. — 提升把声明移到作用域顶部。
- let and const are hoisted but stay in the TDZ. — let 和 const 会被提升但处于 TDZ。
- 地道:hoisted to the top(被提升到顶部)
- 短语:function hoisting · temporal dead zone · var hoisting
13. JSON
- 译:JSON | JS:JavaScript Object Notation,一种轻量级数据交换格式
- 例
- Parse the payload with JSON.parse. — 用 JSON.parse 解析这段数据。
- Send JSON in the request body. — 在请求体里发送 JSON。
- 地道:JSON-serializable(可被 JSON 序列化的)
- 短语:JSON.parse · JSON.stringify · JSON response
14. localStorage
- 译:本地存储 | JS:浏览器中跨会话持久化的键值对存储
- 例
- Store the token in localStorage. — 把 token 存到 localStorage。
- localStorage survives page reloads. — localStorage 在页面刷新后仍然保留。
- 地道:persist in localStorage(持久化到 localStorage)
- 短语:localStorage.getItem · localStorage.setItem · clear localStorage
15. Infinity
- 译:无穷 | JS:表示无穷大的数值常量,大于任何有限数
- 例
- Dividing by zero yields Infinity. — 除以零得到 Infinity。
- Infinity is greater than any finite number. — Infinity 大于任何有限数。
- 地道:loop forever(死循环到无穷)
- 短语:Number.POSITIVE_INFINITY · Infinity vs NaN · 1 / 0
16. navigator
- 译:导航器(浏览器对象,提供 userAgent、clipboard 等信息)
- 短语:navigator.userAgent · navigator.clipboard · window.navigator
17. npm
- 译:npm | JS:Node.js 默认的包管理器和公共注册中心
- 例
- Install the package with npm. — 用 npm 安装这个包。
- Publish the module to the npm registry. — 把模块发布到 npm registry。
- 地道:npm install and go(装好依赖就开干)
- 短语:npm install · package.json · npm scripts
18. performance
- 译:性能 | JS:页面性能监控 API(performance.now、PerformanceObserver)
- 短语:performance.now · Performance API · web performance
19. promise
- 译:承诺;Promise | JS:代表异步操作最终结果的对象,状态一旦落定即不可变
- 例
- A promise settles once: fulfilled or rejected. — 一个 promise 只会落定一次:fulfilled 或 rejected。
- Chain promises with then. — 用 then 串联 promise。
- 地道:settled promise(已落定的 promise)
- 短语:Promise.resolve · Promise.all · pending / fulfilled / rejected
20. prompt
- 译:提示(window.prompt,弹出输入框让用户输入文本)
- 短语:window.prompt · prompt the user · prompt for input
21. prototype
- 译:原型 | JS:对象借以共享属性和方法的机制,构成原型链
- 例
- Every function has a prototype property. — 每个函数都有 prototype 属性。
- Look up properties along the prototype chain. — 沿原型链查找属性。
- 地道:the prototype chain(原型链)
- 短语:prototype chain · Object.getPrototypeOf · proto
22. runtime
- 译:运行时 | JS:执行 JS 代码的环境(浏览器、Node、Deno、Bun 等)
- 例
- Node and the browser are different runtimes. — Node 和浏览器是不同的 runtime。
- The runtime schedules tasks on the event loop. — 运行时把任务调度到事件循环上。
- 地道:at runtime(在运行时)
- 短语:JS runtime · Node runtime · runtime error
23. screen
- 译:屏幕(window.screen,提供分辨率、可用区域等信息)
- 短语:window.screen · screen.width · viewport vs screen
24. scroll
- 译:滚动(滚动页面或元素的内容视图)
- 短语:scroll event · scrollIntoView · smooth scroll
25. typeof
- 译:typeof 运算符 | JS:一元运算符,返回表示操作数类型的字符串
- 例
- typeof null is “object” — a famous JS quirk. — typeof null 是 “object”——一个著名的 JS 怪癖。
- Use typeof to guard against undefined. — 用 typeof 防御 undefined。
- 地道:typeof check(typeof 类型检查)
- 短语:typeof operator · typeof undefined · typeof null
26. undefined
- 译:未定义 | JS:已声明但未赋值的变量的默认值,也是缺失属性访问的结果
- 例
- Uninitialized variables are undefined. — 未初始化的变量值为 undefined。
- Distinguish undefined from null. — 区分 undefined 与 null。
- 地道:void 0 === undefined(void 0 等于 undefined)
- 短语:typeof undefined · undefined vs null · is undefined
27. yield
- 译:产出;让出 | JS:在 generator 函数中产出一个值并暂停执行
- 例
- yield emits a value and pauses the generator. — yield 产出一个值并暂停 generator。
- Use yield* to delegate to another generator. — 用 yield* 委托给另一个 generator。
- 地道:yield control(让出控制权)
- 短语:yield expression · yield* · generator function
28. webpack
- 译:webpack | JS:把模块及其依赖打包成静态资源的前端构建工具
- 例
- Webpack bundles your modules into one file. — webpack 把你的模块打包成一个文件。
- Configure loaders in the webpack config. — 在 webpack 配置中设置 loader。
- 地道:bundle with webpack(用 webpack 打包)
- 短语:webpack config · loaders and plugins · code splitting