uTools-Manuals/docs/javascript/Data_structures.html
2019-04-21 11:50:48 +08:00

315 lines
29 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div></div>
<p>编程语言都具有内建的数据结构,但各种编程语言的数据结构常有不同之处。本文试图列出 JavaScript 语言中内建的数据结构及其属性,它们可以用来构建其他的数据结构;同时尽可能的描述与其他语言的不同之处。</p>
<h2 id="动态类型">动态类型</h2>
<p>JavaScript 是一种<strong>弱类型</strong>或者说<strong>动态</strong>语言。这意味着你不用提前声明变量的类型,在程序运行过程中,类型会被自动确定。这也意味着你可以使用同一个变量保存不同类型的数据:</p>
<pre><code class="language-javascript">var foo = 42; // foo is a Number now
foo = "bar"; // foo is a String now
foo = true; // foo is a Boolean now
</code></pre>
<h2 id="数据类型">数据类型</h2>
<p>最新的 ECMAScript 标准定义了 7 种数据类型:</p>
<ul>
<li>6 种<a class="glossaryLink" href="/en-US/docs/Glossary/Primitive" title="原始类型: In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods. There are 6 primitive data types: string, number, boolean, null, undefined, symbol (new in ECMAScript 2015).">原始类型</a>:
<ul>
<li><a class="glossaryLink" href="/en-US/docs/Glossary/Boolean" title="Boolean: In computer science, a Boolean is a logical data type that can have only the values true or false.">Boolean</a></li>
<li><a class="glossaryLink" href="/en-US/docs/Glossary/Null" title="Null: In computer science, a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address. The meaning of a null reference varies among language implementations.">Null</a></li>
<li><a class="glossaryLink" href="/en-US/docs/Glossary/Undefined" title="Undefined: A primitive value automatically assigned to variables that have just been declared or to formal arguments for which there are no actual arguments.">Undefined</a></li>
<li><a class="glossaryLink" href="/en-US/docs/Glossary/Number" title="Number: In JavaScript, Number is a numeric data type in the double-precision 64-bit floating point format (IEEE 754). In other programming languages different numeric types can exist, for examples: Integers, Floats, Doubles, or Bignums.">Number</a></li>
<li><a class="glossaryLink" href="/en-US/docs/Glossary/String" title="String: In any computer programming language, a string is a sequence of characters used to represent text.">String</a></li>
<li><a class="glossaryLink" href="/en-US/docs/Glossary/Symbol" title="Symbol: In JavaScript, Symbol is a primitive value.">Symbol</a> (ECMAScript 6 新定义)</li>
</ul>
</li>
<li><a class="glossaryLink" href="/en-US/docs/Glossary/Object" title="Object: Object refers to a data structure containing data and instructions for working with the data. Objects sometimes refer to real-world things, for example a car or map object in a racing game. JavaScript, Java, C++, Python, and Ruby are examples of object-oriented programming languages.">Object</a></li>
</ul>
<h2 id="原始值(_primitive_values_)">原始值( primitive values )</h2>
<p>除 Object 以外的所有类型都是不可变的(值本身无法被改变)。例如,与 C 语言不同JavaScript 中字符串是不可变的译注JavaScript 中对字符串的操作一定返回了一个新字符串,原始字符串并没有被改变)。我们称这些类型的值为“原始值”。</p>
<h3 id="布尔类型">布尔类型</h3>
<p>布尔表示一个逻辑实体,可以有两个值:<code>true</code><code>false</code></p>
<h3 id="Null_类型">Null 类型</h3>
<p>Null 类型只有一个值: <code>null</code>,更多详情可查看 <a href="Reference/Global_Objects/null" title="值 null 特指对象的值未设置。它是 JavaScript 基本类型 之一。"><code>null</code></a><a class="glossaryLink" href="/en-US/docs/Glossary/Null" title="Null: In computer science, a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address. The meaning of a null reference varies among language implementations.">Null</a></p>
<h3 id="Undefined_类型">Undefined 类型</h3>
<p>一个没有被赋值的变量会有个默认值 <code>undefined</code>,更多详情可查看 <a href="Reference/Global_Objects/undefined" title="undefined是全局对象的一个属性。也就是说它是全局作用域的一个变量。undefined的最初值就是原始数据类型undefined。"><code>undefined</code></a><a class="glossaryLink" href="/en-US/docs/Glossary/Undefined" title="Undefined: A primitive value automatically assigned to variables that have just been declared or to formal arguments for which there are no actual arguments.">Undefined</a></p>
<h3 id="数字类型">数字类型</h3>
<p>根据 ECMAScript 标准JavaScript 中只有一种数字类型:基于 IEEE 754 标准的双精度 64 位二进制格式的值(-(2<sup>63</sup> -1) 到 2<sup>63</sup> -1<strong>它并没有为整数给出一种特定的类型</strong>。除了能够表示浮点数外,还有一些带符号的值:<code>+Infinity</code><code>-Infinity</code><code>NaN</code> (非数值Not-a-Number)。</p>
<p>要检查值是否大于或小于 <code>+/-Infinity</code>,你可以使用常量 <a href="Reference/Global_Objects/Number/MAX_VALUE" title="Number.MAX_VALUE 属性表示在 JavaScript 里所能表示的最大数值。"><code>Number.MAX_VALUE</code></a><a href="Reference/Global_Objects/Number/MIN_VALUE" title="Number.MIN_VALUE 属性表示在 JavaScript 中所能表示的最小的正值。"><code>Number.MIN_VALUE</code></a>。另外在 ECMAScript 6 中,你也可以通过 <a href="Reference/Global_Objects/Number/isSafeInteger" title="Number.isSafeInteger() 方法用来判断传入的参数值是否是一个“安全整数”safe integer。一个安全整数是一个符合下面条件的整数"><code>Number.isSafeInteger()</code></a> 方法还有 <a href="Reference/Global_Objects/Number/MAX_SAFE_INTEGER" title="Number.MAX_SAFE_INTEGER 常量表示在 JavaScript 中最大的安全整数maxinum safe integer)253 - 1。"><code>Number.MAX_SAFE_INTEGER</code></a><a href="Reference/Global_Objects/Number/MIN_SAFE_INTEGER" title="Number.MIN_SAFE_INTEGER 代表在 JavaScript中最小的安全的integer型数字 (-(253 - 1))."><code>Number.MIN_SAFE_INTEGER</code></a> 来检查值是否在双精度浮点数的取值范围内。 超出这个范围JavaScript 中的数字不再安全了,也就是只有 second mathematical interger 可以在 JavaScript 数字类型中正确表现。</p>
<p>数字类型只有一个整数,它有两种表示方法: 0 可表示为 -0 和 +0"0" 是 +0 的简写)。 在实践中,这也几乎没有影响。 例如 <code>+0 === -0</code> 为真。 但是你可能要注意除以0的时候</p>
<pre><code class="language-javascript">42 / +0; // Infinity
42 / -0; // -Infinity
</code></pre>
<p>尽管一个数字常常仅代表它本身的值但JavaScript提供了一些<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators" title="en/JavaScript/Reference/Operators/Bitwise_Operators">位运算符</a>。 这些位运算符和一个单一数字通过位操作可以用来表现一些布尔值。然而自从 JavaScript 提供其他的方式来表示一组布尔值(如一个布尔值数组或一个布尔值分配给命名属性的对象)后,这种方式通常被认为是不好的。位操作也容易使代码难以阅读,理解和维护, 在一些非常受限的情况下,可能需要用到这些技术,比如试图应付本地存储的存储限制。 位操作只应该是用来优化尺寸的最后选择。</p>
<h3 id="字符串类型">字符串类型</h3>
<p>JavaScript的字符串类型用于表示文本数据。它是一组16位的无符号整数值的“元素”。在字符串中的每个元素占据了字符串的位置。第一个元素的索引为0下一个是索引1依此类推。字符串的长度是它的元素的数量。</p>
<p>不同于类 C 语言JavaScript 字符串是不可更改的。这意味着字符串一旦被创建,就不能被修改。但是,可以基于对原始字符串的操作来创建新的字符串。例如:</p>
<ul>
<li>获取一个字符串的子串可通过选择个别字母或者使用 <a href="Reference/Global_Objects/String/substr" title="substr() 方法返回一个字符串中从指定位置开始到指定字符数的字符。"><code>String.substr()</code></a>.</li>
<li>两个字符串的连接使用连接操作符 (<code>+</code>) 或者 <a href="Reference/Global_Objects/String/concat" title="concat() 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。"><code>String.concat()</code></a>.</li>
</ul>
<h4 id="注意代码中的“字符串类型”!">注意代码中的“字符串类型”!</h4>
<p>可以使用字符串来表达复杂的数据。以下是一些很好的性质:</p>
<ul>
<li>容易连接构造复杂的字串符</li>
<li>字符串容易被调试(你看到的往往在字符串里)</li>
<li>字符串通常是许多APIs的常见标准 (<a href="/en/DOM/HTMLInputElement" title="HTMLInputElement">input fields</a>, <a href="/en/Storage" title="Storage">local storage</a> values, <a href="/zh-CN/docs/Web/API/XMLHttpRequest" title="使用XMLHttpRequest (XHR)对象可以与服务器交互。您可以从URL获取数据而无需让整个的页面刷新。这使得Web页面可以只更新页面的局部而不影响用户的操作。XMLHttpRequest在 Ajax 编程中被大量使用。"><code>XMLHttpRequest</code></a>当使用<code>responseText等</code>的时候回应) 而且他只能与字符串一同使用。</li>
</ul>
<p>按照惯例, 字符串一般可以用来表达任何数据结构。这不是一个好主意。例如,使用一个分隔符,一个可以模仿一个列表(一个JavaScript的数组可能更适合一些) 。不幸的是,当一个分隔符在用于列表中的元素时,打乱了这个列表。 一个转义字符等。所有这些惯例都变成了一个不存在的维护负担而没有正确的工具使用。</p>
<p>表达文本数据和符号数据时候推荐使用字符串。当表达复杂的数据时,使用字符串解析和适当的缩写。</p>
<h3 id="符号类型">符号类型</h3>
<p>符号(Symbols)是ECMAScript 第6版新定义的。符号类型是唯一的并且是不可修改的, 并且也可以用来作为Object的key的值(如下). 在某些语言当中也有类似的原子类型(Atoms). 你也可以认为为它们是C里面的枚举类型. 更多细节请看 <a class="glossaryLink" href="/en-US/docs/Glossary/Symbol" title="Symbol: In JavaScript, Symbol is a primitive value.">Symbol</a> 和 <a href="Reference/Global_Objects/Symbol" title='Symbol()函数会返回symbol类型的值该类型具有静态属性和静态方法。它的静态属性会暴露几个内建的成员对象它的静态方法会暴露全局的symbol注册且类似于内建对象类但作为构造函数来说它并不完整因为它不支持语法"new Symbol()"。'><code>Symbol</code></a></p>
<h2 id="对象">对象</h2>
<p>在计算机科学中, 对象是指内存中的可以被 <a class="glossaryLink" href="/en-US/docs/Glossary/Identifier" title="标识符: A sequence of characters in the code that identifies a variable, function, or property.">标识符</a>引用的一块区域.</p>
<h3 id="属性">属性</h3>
<p>在 Javascript 里,对象可以被看作是一组属性的集合。用<a href="/en/JavaScript/Guide/Values,_variables,_and_literals#Object_literals">对象字面量语法</a>来定义一个对象时会自动初始化一组属性。也就是说你定义一个var a = "Hello"那么a本身就会有a.substring这个方法以及a.length这个属性以及其它如果你定义了一个对象var a = {}那么a就会自动有a.hasOwnProperty及a.constructor等属性和方法。而后这些属性还可以被增减。属性的值可以是任意类型包括具有复杂数据结构的对象。属性使用键来标识它的键值可以是一个字符串或者符号值Symbol</p>
<p>ECMAScript定义的对象中有两种属性数据属性和访问器属性。</p>
<h4 id="数据属性">数据属性</h4>
<p>数据属性是键值对,并且每个数据属性拥有下列特性:</p>
<p><strong>数据属性的特性(<span style="line-height: 1.5;">Attributes of a data property)</span></strong></p>
<table class="standard-table">
<tbody>
<tr>
<th>特性</th>
<th>数据类型</th>
<th>描述</th>
<th>默认值</th>
</tr>
<tr>
<td>[[Value]]</td>
<td>任何Javascript类型</td>
<td>包含这个属性的数据值。</td>
<td>undefined</td>
</tr>
<tr>
<td>[[Writable]]</td>
<td>Boolean</td>
<td>如果该值为 <code>false</code>则该属性的 [[Value]] 特性 不能被改变。</td>
<td>true</td>
</tr>
<tr>
<td>[[Enumerable]]</td>
<td>Boolean</td>
<td>如果该值为 <code>true</code>则该属性可以用 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in">for...in</a> 循环来枚举。</td>
<td>true</td>
</tr>
<tr>
<td>[[Configurable]]</td>
<td>Boolean</td>
<td>如果该值为 <code>false</code>则该属性不能被删除,并且 除了 [[Value]] 和 [[Writable]] 以外的特性都不能被改变。</td>
<td>true</td>
</tr>
</tbody>
</table>
<table class=" standard-table">
<caption>过时的属性(在ECMAScript 3定义的, 在ECMAScript 5被重命名)</caption>
<tbody>
<tr>
<th>属性</th>
<th>类型</th>
<th>描述</th>
</tr>
<tr>
<td>Read-only</td>
<td>Boolean</td>
<td>ES5 [[Writable]] 属性的反状态(Reversed state)</td>
</tr>
<tr>
<td>DontEnum</td>
<td>Boolean</td>
<td>ES5 [[Enumerable]]  属性的反状态</td>
</tr>
<tr>
<td>DontDelete</td>
<td>Boolean</td>
<td>ES5 [[Configurable]] 属性的反状态</td>
</tr>
</tbody>
</table>
<h4 id="访问器属性">访问器属性</h4>
<p>访问器属性有一个或两个访问器函数 (get 和 set) 来存取数值,并且有以下特性:</p>
<table class="standard-table">
<caption>一个访问器属性的特性</caption>
<tbody>
<tr>
<th>特性</th>
<th>类型</th>
<th>描述</th>
<th>默认值</th>
</tr>
<tr>
<td>[[Get]]</td>
<td>函数对象或者 undefined</td>
<td>该函数使用一个空的参数列表,能够在有权访问的情况下读取属性值。另见 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/get">get</a></code></td>
<td>undefined</td>
</tr>
<tr>
<td>[[Set]]</td>
<td>函数对象或者 undefined</td>
<td>该函数有一个参数,用来写入属性值,另见 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/set">set</a></code></td>
<td>undefined</td>
</tr>
<tr>
<td>[[Enumerable]]</td>
<td>Boolean</td>
<td>如果该值为 <code>true则该属性可以用</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in">for...in</a> 循环来枚举。</td>
<td>true</td>
</tr>
<tr>
<td>[[Configurable]]</td>
<td>Boolean</td>
<td>如果该值为 <code>false则该属性不能被删除并且不能被转变成一个数据属性。</code></td>
<td>true</td>
</tr>
</tbody>
</table>
<div class="note">
<p>注意:这些特性只有 JavaScript 引擎才用到,因此你不能直接访问它们。所以特性被放在两对方括号中,而不是一对。</p>
</div>
<h3 id="标准的_对象_和函数">"标准的" 对象, 和函数</h3>
<p>一个 Javascript 对象就是键和值之间的映射.。键是一个字符串(或者 <a href="Reference/Global_Objects/Symbol" title='Symbol()函数会返回symbol类型的值该类型具有静态属性和静态方法。它的静态属性会暴露几个内建的成员对象它的静态方法会暴露全局的symbol注册且类似于内建对象类但作为构造函数来说它并不完整因为它不支持语法"new Symbol()"。'><code>Symbol</code></a> ,值可以是任意类型的值。 这使得对象非常符合 <a class="external" href="http://en.wikipedia.org/wiki/Hash_table" rel="noopener">哈希表</a></p>
<p>函数是一个附带可被调用功能的常规对象。</p>
<h3 id="日期">日期</h3>
<p>当你想要显示日期时,毋庸置疑,使用内建的 <a href="/en/JavaScript/Reference/Global_Objects/Date">Date</a> 对象。</p>
<h3 id="有序集_数组和类型数组">有序集: 数组和类型数组</h3>
<p><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array" title="Array">数组</a>是一种使用整数作为键(integer-key-ed)属性和长度(length)属性之间关联的常规对象。此外,数组对象还继承了 Array.prototype 的一些操作数组的便捷方法。例如, <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf" title="en/JavaScript/Reference/Global_Objects/Array/indexOf">indexOf</a></code> (搜索数组中的一个值) or <code><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/push" title="en/JavaScript/Reference/Global_Objects/Array/push">push</a></code> (向数组中添加一个元素),等等。 这使得数组是表示列表或集合的最优选择。</p>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays">类型数组(Typed Arrays)</a>是ECMAScript Edition 6中新定义的 JavaScript 内建对象,提供了一个基本的二进制数据缓冲区的类数组视图。下面的表格能帮助你找到对等的 C 语言数据类型:</p>
<p></p><h4 id="TypedArray_objects">TypedArray objects</h4>
<table class="standard-table">
<tbody>
<tr>
<td class="header">Type</td>
<td class="header">Value Range</td>
<td class="header">Size in bytes</td>
<td class="header">Description</td>
<td class="header">Web IDL type</td>
<td class="header">Equivalent C type</td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array" title="The Int8Array typed array represents an array of twos-complement 8-bit signed integers. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation)."><code>Int8Array</code></a></td>
<td>-128 to 127</td>
<td>1</td>
<td>8-bit two's complement signed integer</td>
<td><code>byte</code></td>
<td><code>int8_t</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" title="The Uint8Array typed array represents an array of 8-bit unsigned integers. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation)."><code>Uint8Array</code></a></td>
<td>0 to 255</td>
<td>1</td>
<td>8-bit unsigned integer</td>
<td><code>octet</code></td>
<td><code>uint8_t</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray" title="The Uint8ClampedArray typed array represents an array of 8-bit unsigned integers clamped to 0-255; if you specified a value that is out of the range of [0,255], 0 or 255 will be set instead; if you specify a non-integer, the nearest integer will be set. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation)."><code>Uint8ClampedArray</code></a></td>
<td>0 to 255</td>
<td>1</td>
<td>8-bit unsigned integer (clamped)</td>
<td><code>octet</code></td>
<td><code>uint8_t</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array" title="The Int16Array typed array represents an array of twos-complement 16-bit signed integers in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation)."><code>Int16Array</code></a></td>
<td>-32768 to 32767</td>
<td>2</td>
<td>16-bit two's complement signed integer</td>
<td><code>short</code></td>
<td><code>int16_t</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array" title="The Uint16Array typed array represents an array of 16-bit unsigned integers in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation)."><code>Uint16Array</code></a></td>
<td>0 to 65535</td>
<td>2</td>
<td>16-bit unsigned integer</td>
<td><code>unsigned short</code></td>
<td><code>uint16_t</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array" title="The Int32Array typed array represents an array of twos-complement 32-bit signed integers in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation)."><code>Int32Array</code></a></td>
<td>-2147483648 to 2147483647</td>
<td>4</td>
<td>32-bit two's complement signed integer</td>
<td><code>long</code></td>
<td><code>int32_t</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array" title="The Uint32Array typed array represents an array of 32-bit unsigned integers in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation)."><code>Uint32Array</code></a></td>
<td>0 to 4294967295</td>
<td>4</td>
<td>32-bit unsigned integer</td>
<td><code>unsigned long</code></td>
<td><code>uint32_t</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array" title="The Float32Array typed array represents an array of 32-bit floating point numbers (corresponding to the C float data type) in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation)."><code>Float32Array</code></a></td>
<td>1.2x10<sup>-38</sup> to 3.4x10<sup>38</sup></td>
<td>4</td>
<td>32-bit IEEE floating point number ( 7 significant digits e.g. 1.1234567)</td>
<td><code>unrestricted float</code></td>
<td><code>float</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array" title="The Float64Array typed array represents an array of 64-bit floating point numbers (corresponding to the C double data type) in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation)."><code>Float64Array</code></a></td>
<td>5.0x10<sup>-324</sup> to 1.8x10<sup>308</sup></td>
<td>8</td>
<td>64-bit IEEE floating point number (16 significant digits e.g. 1.123...15)</td>
<td><code>unrestricted double</code></td>
<td><code>double</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array" title="content here."><code>BigInt64Array</code></a></td>
<td>-2<sup>63</sup> to 2<sup>63</sup>-1</td>
<td>8</td>
<td>64-bit two's complement signed integer</td>
<td><code>bigint</code></td>
<td><code>int64_t (signed long long)</code></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array" title="content here."><code>BigUint64Array</code></a></td>
<td>0 to 2<sup>64</sup>-1</td>
<td>8</td>
<td>64-bit unsigned integer</td>
<td><code>bigint</code></td>
<td><code>uint64_t (unsigned long long)</code></td>
</tr>
</tbody>
</table><p></p>
<h3 id="键控集_Maps_Sets_WeakMaps_WeakSets">键控集: Maps, Sets, WeakMaps, WeakSets</h3>
<p>这些数据结构把对象的引用当作键其在ECMAScript第6版中有介绍。当 <a href="Reference/Map" title="此页面仍未被本地化, 期待您的翻译!"><code>Map</code></a><a href="Reference/WeakMap" title="此页面仍未被本地化, 期待您的翻译!"><code>WeakMap</code></a> 把一个值和对象关联起来的时候, <a href="Reference/Global_Objects/Set" title="Set 对象允许你存储任何类型的唯一值无论是原始值或者是对象引用。"><code>Set</code></a><a href="Reference/Global_Objects/WeakSet" title="WeakSet 对象允许你将弱保持对象存储在一个集合中。"><code>WeakSet</code></a> 表示一组对象。 Map和WeakMaps之间的差别在于在前者中对象键是可枚举的。这允许垃圾收集器优化后面的枚举(This allows garbage collection optimizations in the latter case)。</p>
<p>在纯ECMAScript 5下可以实现Maps和Sets。然而因为对象并不能进行比较就对象“小于”示例来讲所以查询必定是线性的。他们本地实现包括WeakMaps查询所花费的时间可能是对数增长。</p>
<p>通常可以通过直接在对象上设置属性或着使用data-*属性来绑定数据到DOM节点。然而缺陷是在任何的脚本里数据都运行在同样的上下文中。Maps和WeakMaps方便将数据私密的绑定到一个对象。 </p>
<h3 id="结构化数据_JSON">结构化数据: JSON</h3>
<p>JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式,来源于 JavaScript 同时也被多种语言所使用。 JSON 用于构建通用的数据结构。参见 <a class="glossaryLink" href="/en-US/docs/Glossary/JSON" title="JSON: JavaScript Object Notation (JSON) is a data-interchange format.  Although not a strict subset, JSON closely resembles a subset of JavaScript syntax. Though many programming languages support JSON, JSON is especially useful for JavaScript-based apps, including websites and browser extensions.">JSON</a> 以及 <a href="Reference/Global_Objects/JSON" title="JSON对象包含两个方法: 用于解析 JavaScript Object Notation  (JSON) 的 parse() 方法,以及将对象/值转换为 JSON字符串的 stringify() 方法。除了这两个方法, JSON这个对象本身并没有其他作用也不能被调用或者作为构造函数调用。"><code>JSON</code></a> 了解更多。</p>
<h3 id="标准库中更多的对象">标准库中更多的对象</h3>
<p>JavaScript 有一个内置对象的标准库。请查看<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects">参考</a>来了解更多对象。</p>
<h2 id="使用_typeof_操作符判断对象类型">使用 typeof 操作符判断对象类型</h2>
<p>typeof 运算符可以帮助你查询变量的类型。要了解更多细节和注意事项请阅读<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof">参考页</a></p>
<h2 id="规范">规范</h2>
<table class=" standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">注释</th>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,%20June%201997.pdf" hreflang="en" lang="en" rel="noopener" title="ECMAScript 1st Edition (ECMA-262)">ECMAScript 1st Edition (ECMA-262)</a></td>
<td><span class="spec-Standard">Standard</span></td>
<td>初始定义</td>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/ecma-262/5.1/#sec-8" hreflang="en" lang="en" rel="noopener">ECMAScript 5.1 (ECMA-262)<br/><small lang="zh-CN">Types</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td> </td>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-data-types-and-values" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">ECMAScript Data Types and Values</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="参考资料">参考资料</h2>
<ul>
<li><a class="external link-https" href="https://github.com/nzakas/computer-science-in-javascript/" rel="noopener">Nicholas Zakas collection of common data structure and common algorithms in JavaScript.</a></li>
<li><a class="external" href="https://github.com/monmohan/DataStructures_In_Javascript" rel="noopener" title="https://github.com/monmohan/DataStructures_In_Javascript">Search Tre(i)es implemented in JavaScript</a></li>
</ul>
</article>