标准内置对象

本章记录了所有 JavaScript 的标准内置对象,包括它们的方法和属性。

¥This chapter documents all of JavaScript's standard, built-in objects, including their methods and properties.

这里的术语 "全局对象"(或标准内置对象)不要与全局对象混淆。这里,"全局对象" 指的是全局范围内的对象。

¥The term "global objects" (or standard built-in objects) here is not to be confused with the global object. Here, "global objects" refer to objects in the global scope.

可以在全局范围内使用 this 运算符来访问全局对象本身。事实上,全局范围由全局对象的属性组成,包括继承的属性(如果有)。

¥The global object itself can be accessed using the this operator in the global scope. In fact, the global scope consists of the properties of the global object, including inherited properties, if any.

全局范围内的其他对象要么是 由用户脚本创建,要么是由主机应用提供。浏览器上下文中可用的主机对象记录在 API 参考

¥Other objects in the global scope are either created by the user script or provided by the host application. The host objects available in browser contexts are documented in the API reference.

有关 DOM 和核心 JavaScript 之间区别的更多信息,请参阅 JavaScript 技术概述

¥For more information about the distinction between the DOM and core JavaScript, see JavaScript technologies overview.

按类别划分的标准对象

¥Standard objects by category

值属性

¥Value properties

这些全局属性返回一个简单的值。它们没有属性或方法。

¥These global properties return a simple value. They have no properties or methods.

函数属性

¥Function properties

这些全局函数(全局调用的函数,而不是在对象上调用的函数)直接将其结果返回给调用者。

¥These global functions—functions which are called globally, rather than on an object—directly return their results to the caller.

基本对象

¥Fundamental objects

这些对象代表基本的语言结构。

¥These objects represent fundamental language constructs.

错误对象

¥Error objects

错误对象是一种特殊类型的基本对象。它们包括基本的 Error 类型,以及几个专门的错误类型。

¥Error objects are a special type of fundamental object. They include the basic Error type, as well as several specialized error types.

数字和日期

¥Numbers and dates

这些是表示数字、日期和数学计算的基础对象。

¥These are the base objects representing numbers, dates, and mathematical calculations.

文本处理

¥Text processing

这些对象表示字符串并支持对它们进行操作。

¥These objects represent strings and support manipulating them.

索引集合

¥Indexed collections

这些对象表示按索引值排序的数据集合。这包括(类型化)数组和类似数组的结构。

¥These objects represent collections of data which are ordered by an index value. This includes (typed) arrays and array-like constructs.

键控集合

¥Keyed collections

这些对象代表使用键的集合。可迭代集合(MapSet)包含可以按插入顺序轻松迭代的元素。

¥These objects represent collections which use keys. The iterable collections (Map and Set) contain elements which are easily iterated in the order of insertion.

结构化数据

¥Structured data

这些对象表示结构化数据缓冲区和使用 JavaScript 对象表示法 (JSON) 编码的数据并与之交互。

¥These objects represent and interact with structured data buffers and data coded using JavaScript Object Notation (JSON).

管理内存

¥Managing memory

这些对象与垃圾收集机制交互。

¥These objects interact with the garbage collection mechanism.

控制抽象对象

¥Control abstraction objects

控制抽象可以帮助构建代码,尤其是异步代码(例如,不使用深度嵌套的回调)。

¥Control abstractions can help to structure code, especially async code (without using deeply nested callbacks, for example).

反射

¥Reflection

国际化

¥Internationalization

添加了 ECMAScript 核心以实现语言敏感的功能。

¥Additions to the ECMAScript core for language-sensitive functionalities.