home / documentation / v16 / globals

Global objects

目录

自 v0.10.0 版本开始新增

These objects are available in all modules. The following variables may appear to be global but are not. They exist only in the scope of modules, see the module system documentation:

The objects listed here are specific to Node.js. There are built-in objects that are part of the JavaScript language itself, which are also globally accessible.

C AbortController

历史
版本历史变更
v15.4.0No longer experimental.
v15.0.0自 v15.0.0 版本开始新增

A utility class used to signal cancelation in selected Promise-based APIs. The API is based on the Web API AbortController.

JS

M abortController.abort([reason])

历史
版本历史变更
v16.14.0Added the new optional reason argument.
v15.0.0, v14.17.0自 v15.0.0, v14.17.0 版本开始新增
  • reason any An optional reason, retrievable on the AbortSignal's reason property.

Triggers the abort signal, causing the abortController.signal to emit the 'abort' event.

M abortController.signal

自 v15.0.0 版本开始新增

C AbortSignal

自 v15.0.0 版本开始新增

The AbortSignal is used to notify observers when the abortController.abort() method is called.

Static method: AbortSignal.abort([reason])
历史
版本历史变更
v16.14.0Added the new optional reason argument.
v15.12.0, v14.17.0自 v15.12.0, v14.17.0 版本开始新增

Returns a new already aborted AbortSignal.

Static method: AbortSignal.timeout(delay)

自 v16.14.0 版本开始新增

  • delay number The number of milliseconds to wait before triggering the AbortSignal.

Returns a new AbortSignal which will be aborted in delay milliseconds.

E 'abort'

自 v15.0.0 版本开始新增

The 'abort' event is emitted when the abortController.abort() method is called. The callback is invoked with a single object argument with a single type property set to 'abort':

JS

The AbortController with which the AbortSignal is associated will only ever trigger the 'abort' event once. We recommended that code check that the abortSignal.aborted attribute is false before adding an 'abort' event listener.

Any event listeners attached to the AbortSignal should use the { once: true } option (or, if using the EventEmitter APIs to attach a listener, use the once() method) to ensure that the event listener is removed as soon as the 'abort' event is handled. Failure to do so may result in memory leaks.

M abortSignal.aborted

自 v15.0.0 版本开始新增

  • Type: boolean True after the AbortController has been aborted.
M abortSignal.onabort

自 v15.0.0 版本开始新增

An optional callback function that may be set by user code to be notified when the abortController.abort() function has been called.

M abortSignal.reason

自 v16.14.0 版本开始新增

An optional reason specified when the AbortSignal was triggered.

JS
M abortSignal.throwIfAborted()

自 v16.17.0 版本开始新增

If abortSignal.aborted is true, throws abortSignal.reason.

C Buffer

自 v0.1.103 版本开始新增

Used to handle binary data. See the buffer section.

M __dirname

This variable may appear to be global but is not. See __dirname.

M __filename

This variable may appear to be global but is not. See __filename.

M atob(data)

自 v16.0.0 版本开始新增

稳定级别:3 - Legacy. Use `Buffer.from(data, 'base64')` instead.

Global alias for buffer.atob().

M btoa(data)

自 v16.0.0 版本开始新增

稳定级别:3 - Legacy. Use `buf.toString('base64')` instead.

Global alias for buffer.btoa().

M clearImmediate(immediateObject)

自 v0.9.1 版本开始新增

clearImmediate is described in the timers section.

M clearInterval(intervalObject)

自 v0.0.1 版本开始新增

clearInterval is described in the timers section.

M clearTimeout(timeoutObject)

自 v0.0.1 版本开始新增

clearTimeout is described in the timers section.

M console

自 v0.1.100 版本开始新增

Used to print to stdout and stderr. See the console section.

M Crypto

自 v16.15.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-global-webcrypto` CLI flag.

A browser-compatible implementation of Crypto. This global is available only if the Node.js binary was compiled with including support for the node:crypto module.

M crypto

自 v16.15.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-global-webcrypto` CLI flag.

A browser-compatible implementation of the Web Crypto API.

M CryptoKey

自 v16.15.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-global-webcrypto` CLI flag.

A browser-compatible implementation of CryptoKey. This global is available only if the Node.js binary was compiled with including support for the node:crypto module.

M CustomEvent

自 v16.17.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-global-customevent` CLI flag.

A browser-compatible implementation of the CustomEvent Web API.

M Event

历史
版本历史变更
v15.4.0No longer experimental.
v15.0.0自 v15.0.0 版本开始新增

A browser-compatible implementation of the Event class. See EventTarget and Event API for more details.

M EventTarget

历史
版本历史变更
v15.4.0No longer experimental.
v15.0.0自 v15.0.0 版本开始新增

A browser-compatible implementation of the EventTarget class. See EventTarget and Event API for more details.

M exports

This variable may appear to be global but is not. See exports.

M fetch

自 v16.15.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-fetch` CLI flag.

A browser-compatible implementation of the fetch() function.

Class FormData

自 v16.15.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-fetch` CLI flag.

A browser-compatible implementation of FormData.

M global

自 v0.1.27 版本开始新增

  • Object The global namespace object.

In browsers, the top-level scope is the global scope. This means that within the browser var something will define a new global variable. In Node.js this is different. The top-level scope is not the global scope; var something inside a Node.js module will be local to that module.

Class Headers

自 v16.15.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-fetch` CLI flag.

A browser-compatible implementation of Headers.

M MessageChannel

自 v15.0.0 版本开始新增

The MessageChannel class. See MessageChannel for more details.

M MessageEvent

自 v15.0.0 版本开始新增

The MessageEvent class. See MessageEvent for more details.

M MessagePort

自 v15.0.0 版本开始新增

The MessagePort class. See MessagePort for more details.

M module

This variable may appear to be global but is not. See module.

M performance

自 v16.0.0 版本开始新增

The perf_hooks.performance object.

M process

自 v0.1.7 版本开始新增

The process object. See the process object section.

M queueMicrotask(callback)

自 v11.0.0 版本开始新增

  • callback Function Function to be queued.

The queueMicrotask() method queues a microtask to invoke callback. If callback throws an exception, the process object 'uncaughtException' event will be emitted.

The microtask queue is managed by V8 and may be used in a similar manner to the process.nextTick() queue, which is managed by Node.js. The process.nextTick() queue is always processed before the microtask queue within each turn of the Node.js event loop.

JS

M require()

This variable may appear to be global but is not. See require().

M Response

自 v16.15.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-fetch` CLI flag.

A browser-compatible implementation of Response.

M Request

自 v16.15.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-fetch` CLI flag.

A browser-compatible implementation of Request.

M setImmediate(callback[, ...args])

自 v0.9.1 版本开始新增

setImmediate is described in the timers section.

M setInterval(callback, delay[, ...args])

自 v0.0.1 版本开始新增

setInterval is described in the timers section.

M setTimeout(callback, delay[, ...args])

自 v0.0.1 版本开始新增

setTimeout is described in the timers section.

M SubtleCrypto

自 v16.15.0 版本开始新增

稳定级别:1 - Experimental. Enable this API with the `--experimental-global-webcrypto` CLI flag.

A browser-compatible implementation of SubtleCrypto. This global is available only if the Node.js binary was compiled with including support for the node:crypto module.

M TextDecoder

自 v11.0.0 版本开始新增

The WHATWG TextDecoder class. See the TextDecoder section.

M TextEncoder

自 v11.0.0 版本开始新增

The WHATWG TextEncoder class. See the TextEncoder section.

M URL

自 v10.0.0 版本开始新增

The WHATWG URL class. See the URL section.

M URLSearchParams

自 v10.0.0 版本开始新增

The WHATWG URLSearchParams class. See the URLSearchParams section.

M WebAssembly

自 v8.0.0 版本开始新增

The object that acts as the namespace for all W3C WebAssembly related functionality. See the Mozilla Developer Network for usage and compatibility.