2019-04-21 11:50:48 +08:00

233 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><strong><code>Int8Array</code></strong> 类型数组表示二进制补码8位有符号整数的数组。内容初始化为0。 一旦建立你可以使用对象的方法引用数组中的元素或使用标准数组索引语法( 即,使用括号注释)。</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript">new Int8Array(length);
new Int8Array(typedArray);
new Int8Array(object);
new Int8Array(buffer [, byteOffset [, length]]);</code></pre>
<p>有关构造函数语法和参数的更多信息,请访问 <em><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Syntax">TypedArray</a></em>.</p>
<h2 id="属性">属性</h2>
<dl>
<dt><a href="Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT" title="TypedArray.BYTES_PER_ELEMENT 属性代表了强类型数组中每个元素所占用的字节数。"><code>Int8Array.BYTES_PER_ELEMENT</code></a></dt>
<dd>返回数组中每个元素的大小. 在<code>Int8Array中这个值为1</code>.</dd>
<dt>Int8Array.length</dt>
<dd>此属性为固定值属性值为3.查看 <a href="Reference/Global_Objects/TypedArray/length" title="length访问器属性表示类型化数组的长度元素数。"><code>Int8Array.prototype.length</code></a>获得获取数组内元素个数方法。</dd>
<dt><a href="Reference/Global_Objects/TypedArray/name" title="TypedArray.name ?属性是描述类型数组构造名的字符串值。"><code>Int8Array.name</code></a></dt>
<dd>返回构造器方法名称.在Int8Array类型中此值为 "Int8Array"。</dd>
<dt><a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>Int8Array.prototype</code></a></dt>
<dd><em>TypedArray</em> 对象的构造原型。</dd>
</dl>
<h2 id="方法">方法</h2>
<dl>
<dt><a href="Reference/Global_Objects/TypedArray/from" title="TypedArray.from() 方法 从一个类数组或者可迭代对象中创建一个新类型数组。 这个方法和 Array.from()类似。"><code>Int8Array.from()</code></a></dt>
<dd>从类数组对象或迭代器生成int8Array数组对象. 参照<a href="Reference/Global_Objects/Array/from" title="Array.from() 方法从一个类似数组或可迭代对象中创建一个新的数组实例。"><code>Array.from()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/of" title="TypedArray.of() 方法创建一个具有可变数量参数的新类型数组 。此方法几乎与Array.of() 相同。"><code>Int8Array.of()</code></a></dt>
<dd>以多个参数构造Int8Array对象 参照 <a href="Reference/Global_Objects/Array/of" title="Array.of() 方法创建一个具有可变数量参数的新数组实例,而不考虑参数的数量或类型。"><code>Array.of()</code></a>.</dd>
</dl>
<h2 id="Int8Array_原型方法"><code>Int8Array</code> 原型方法</h2>
<p>所有<strong> Int8Array</strong>对象都继承自 <a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>%TypedArray%.prototype</code></a>.</p>
<h3 id="属性_2">属性</h3>
<dl>
<dt><code>Int8Array.prototype.constructor</code></dt>
<dd>这个方法会返回对象的构造原型. 默认为<code>Int8Array构造函数</code>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/buffer" title="buffer访问器属性表示由TypedArray在构造期间引用的ArrayBuffer。"><code>Int8Array.prototype.buffer</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the <a href="Reference/Global_Objects/ArrayBuffer" title="The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>ArrayBuffer</code></a> referenced by the <code>Int8Array</code> Fixed at construction time and thus <strong>read only</strong>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/byteLength" title="byteLength访问器属性表示类型化数组的长度字节数。"><code>Int8Array.prototype.byteLength</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the length (in bytes) of the <code>Int8Array</code> from the start of its <a href="Reference/Global_Objects/ArrayBuffer" title="The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>ArrayBuffer</code></a>. Fixed at construction time and thus <strong>read only.</strong></dd>
<dt><a href="Reference/Global_Objects/TypedArray/byteOffset" title="byteOffset 访问器属性表示类型化数组距离其ArrayBuffer起始位置的偏移字节数。"><code>Int8Array.prototype.byteOffset</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the offset (in bytes) of the <code>Int8Array</code> from the start of its <a href="Reference/Global_Objects/ArrayBuffer" title="The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>ArrayBuffer</code></a>. Fixed at construction time and thus <strong>read only.</strong></dd>
<dt><a href="Reference/Global_Objects/TypedArray/length" title="length访问器属性表示类型化数组的长度元素数。"><code>Int8Array.prototype.length</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the number of elements hold in the <code>Int8Array</code>. Fixed at construction time and thus <strong>read only.</strong></dd>
</dl>
<h3 id="方法_2">方法</h3>
<dl>
<dt><a href="Reference/Global_Objects/TypedArray/copyWithin" title="copyWithin()方法将数组中的元素序列复制到以target起始的位置。 副本取自第二个参数和第三个参数 start 和end的位置下标。end 参数是可选的默认为数组长度。这个方法的算法和Array.prototype.copyWithin相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.copyWithin()</code></a></dt>
<dd>Copies a sequence of array elements within the array. See also <a href="Reference/Global_Objects/Array/copyWithin" title="改变了的数组。"><code>Array.prototype.copyWithin()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/entries" title="The entries()返回新的Array Iterator对象包含数组每个下标处的键值对。"><code>Int8Array.prototype.entries()</code></a></dt>
<dd>Returns a new <code>Array Iterator</code> object that contains the key/value pairs for each index in the array. See also <a href="Reference/Global_Objects/Array/entries" title="entries() 方法返回一个新的Array Iterator对象该对象包含数组中每个索引的键/值对。"><code>Array.prototype.entries()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/every" title="every() 方法测试类型化数组的所有元素是否都能够通过由提供函数实现的测试。这个方法的算法与 Array.prototype.every()相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.every()</code></a></dt>
<dd>Tests whether all elements in the array pass the test provided by a function. See also <a href="Reference/Global_Objects/Array/every" title="every() 方法测试数组的所有元素是否都通过了指定函数的测试。"><code>Array.prototype.every()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/fill" title="fill() 方法将类型化数组中的从起始索引到终止索引内的全部元素。这个方法的算法和 Array.prototype.fill() 相同。 TypedArray 是这里的类型化数组类型之一。"><code>Int8Array.prototype.fill()</code></a></dt>
<dd>Fills all the elements of an array from a start index to an end index with a static value. See also <a href="Reference/Global_Objects/Array/fill" title="fill() 方法用一个固定值填充一个数组中从起始索引到终止索引内的全部元素。不包括终止索引。"><code>Array.prototype.fill()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/filter" title="filter()创建新的类型化数组,含有所有通过了测试的元素,测试由提供的函数实现。这个方法的算法和 Array.prototype.filter()相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.filter()</code></a></dt>
<dd>Creates a new array with all of the elements of this array for which the provided filtering function returns true. See also <a href="Reference/Global_Objects/Array/filter" title="filter() 方法创建一个新数组, 其包含通过所提供函数实现的测试的所有元素。"><code>Array.prototype.filter()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/find" title="如果某个元素满足所提供的测试函数find()方法返回类型化数组中的 值。否则返回undefined 。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.find()</code></a></dt>
<dd>Returns the found value in the array, if an element in the array satisfies the provided testing function or <code>undefined</code> if not found. See also <a href="Reference/Global_Objects/Array/find" title="find() 方法返回数组中满足提供的测试函数的第一个元素的值。否则返回 undefined。"><code>Array.prototype.find()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/findIndex" title="如果某个元素满足所提供的测试函数findIndex()方法返回类型化数组中的 下标。否则返回 -1。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.findIndex()</code></a></dt>
<dd>Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found. See also <a href="Reference/Global_Objects/Array/findIndex" title="findIndex()方法返回数组中满足提供的测试函数的第一个元素的索引。否则返回-1。"><code>Array.prototype.findIndex()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/forEach" title="forEach()方法对类型化数组的每个元素调用提供的函数。 这个方法的算法和 Array.prototype.forEach()相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.forEach()</code></a></dt>
<dd>Calls a function for each element in the array. See also <a href="Reference/Global_Objects/Array/forEach" title="forEach() 方法对数组的每个元素执行一次提供的函数。"><code>Array.prototype.forEach()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/includes" title="includes()方法判断类型化数组中是否含有特定元素并相应返回true 或者false 这个方法的算法和Array.prototype.includes()相同。 TypedArray 是这里的 类型化数组 之一。"><code>Int8Array.prototype.includes()</code></a> <span title="这是一个实验性的 API请尽量不要在生产环境中使用它。"><i class="icon-beaker"> </i></span></dt>
<dd>Determines whether a typed array includes a certain element, returning <code>true</code> or <code>false</code> as appropriate. See also <a href="Reference/Global_Objects/Array/includes" title="includes() 方法用来判断一个数组是否包含一个指定的值,根据情况,如果包含则返回 true否则返回false。"><code>Array.prototype.includes()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/indexOf" title="indexOf() 方法返回在类型数组中可以找到给定元素的第一个索引,如果不存在,则返回-1。 方法具有与 Array.prototype.indexOf() 相同的算法。 TypedArray是这里的类型化数组类型之一。"><code>Int8Array.prototype.indexOf()</code></a></dt>
<dd>Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found. See also <a href="Reference/Global_Objects/Array/indexOf" title="indexOf()方法返回在数组中可以找到一个给定元素的第一个索引,如果不存在,则返回-1。"><code>Array.prototype.indexOf()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/join" title="join()方法将数组中所有元素连接为一个字符串。这个方法的算法和Array.prototype.join()相同。 TypedArray 是这里的 类型化数组 之一。"><code>Int8Array.prototype.join()</code></a></dt>
<dd>Joins all elements of an array into a string. See also <a href="Reference/Global_Objects/Array/join" title="join() 方法将一个数组(或一个类数组对象)的所有元素连接成一个字符串并返回这个字符串。如果数组只有一个项目,那么将返回该项目而不使用分隔符。"><code>Array.prototype.join()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/keys" title="keys()方法返回新的 Array Iterator 对象,包含数组中每个下标的键。"><code>Int8Array.prototype.keys()</code></a></dt>
<dd>Returns a new <code>Array Iterator</code> that contains the keys for each index in the array. See also <a href="Reference/Global_Objects/Array/keys" title="keys() 方法返回一个包含数组中每个索引键的Array Iterator对象。"><code>Array.prototype.keys()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/lastIndexOf" title="lastIndexOf() 方法返回在类型数组中可以找到给定元素的最后一个索引,如果不存在,则返回-1。 方法具有与 Array.prototype.lastIndexOf() 相同的算法。 TypedArray是这里的类型化数组类型之一。"><code>Int8Array.prototype.lastIndexOf()</code></a></dt>
<dd>Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found. See also <a href="Reference/Global_Objects/Array/lastIndexOf" title="lastIndexOf() 方法返回指定元素(也即有效的 JavaScript 值或变量)在数组中的最后一个的索引,如果不存在则返回 -1。从数组的后面向前查找从 fromIndex 处开始。"><code>Array.prototype.lastIndexOf()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/map" title="map()方法对类型化数组的每个元素调用提供的函数,并使用结果来创建新的类型化数组。 这个方法的算法和 Array.prototype.map()相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.map()</code></a></dt>
<dd>返回一个由回调函数的返回值组成的新数组。. See also <a href="Reference/Global_Objects/Array/map" title="map() 方法创建一个新数组,其结果是该数组中的每个元素都调用一个提供的函数后返回的结果。"><code>Array.prototype.map()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/move" title="move()方法将数组中的元素序列复制到以target起始的位置。但是这个非标准方法已经被TypedArray.prototype.copyWithin() 标准方法取代。TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.move()</code></a> <span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> <span class="inlineIndicator unimplemented unimplementedInline">未实现</span></dt>
<dd><a href="Reference/Global_Objects/TypedArray/copyWithin" title="copyWithin()方法将数组中的元素序列复制到以target起始的位置。 副本取自第二个参数和第三个参数 start 和end的位置下标。end 参数是可选的默认为数组长度。这个方法的算法和Array.prototype.copyWithin相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.copyWithin()</code></a> 早期的不标准定义。</dd>
<dt><a href="Reference/Global_Objects/TypedArray/reduce" title="reduce() 方法接受一个函数作为参数,这个函数作为一个累加器,从左到右遍历整个类型数组,最后返回一个单一的值. 这个方法和Array.prototype.reduce()使用了同样的算法. TypedArray 是一个 类型数组."><code>Int8Array.prototype.reduce()</code></a></dt>
<dd>从左到右为每个数组元素执行一次回调函数,并把上次回调函数的返回值放在一个暂存器中传给下次回调函数,并返回最后一次回调函数的返回值。参照 <a href="Reference/Global_Objects/Array/reduce" title="reduce() 方法对数组中的每个元素执行一个由您提供的reducer函数(升序执行),将其结果汇总为单个返回值。"><code>Array.prototype.reduce()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/reduceRight" title="reduceRight()在累加器和类型化数组的每个元素上(从右到左)调用函数,使其归约为单一的值。这个方法的算法和 Array.prototype.reduceRight()相同。 TypedArray 是这里的类型化数组类型 之一。"><code>Int8Array.prototype.reduceRight()</code></a></dt>
<dd>从右到左为每个数组元素执行一次回调函数,并把上次回调函数的返回值放在一个暂存器中传给下次回调函数,并返回最后一次回调函数的返回值。参照 <a href="Reference/Global_Objects/Array/reduceRight" title="reduceRight() 方法接受一个函数作为累加器accumulator和数组的每个值从右到左将其减少为单个值。"><code>Array.prototype.reduceRight()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/reverse" title="reverse()方法原地翻转类型化数组。类型化数组的第一个元素变为最后一个最后一个变为第一个。这个方法的算法和Array.prototype.reverse()相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.reverse()</code></a></dt>
<dd>颠倒数组中元素的排列顺序,即原先的第一个变为最后一个,原先的最后一个变为第一个。参照<a href="Reference/Global_Objects/Array/reverse" title="reverse() 方法将数组中元素的位置颠倒。"><code>Array.prototype.reverse()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/set" title="set() 方法用于从指定数组中读取值,并将其存储在类型化数组中。"><code>Int8Array.prototype.set()</code></a></dt>
<dd>Stores multiple values in the typed array, reading input values from a specified array.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/slice" title="slice()方法返回一个typed array的部分类型数组对象数组内容采用浅拷贝方式. 方法采用与 Array.prototype.slice()相同的算法. 类型数组是 typed array types成员中的一员 ."><code>Int8Array.prototype.slice()</code></a></dt>
<dd>抽取当前数组中的一段元素组合成一个新数组。参照<a href="Reference/Global_Objects/Array/slice" title="The source for this interactive demo is stored in a GitHub repository. If you'd like to contribute to the interactive demo project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>Array.prototype.slice()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/some" title="这个 some() 方法检测 TypedArray 的一些元素是否通过所提供函数的测试. 这个方法和 Array.prototype.some() 相同. TypedArray 是 typed array types 之一."><code>Int8Array.prototype.some()</code></a></dt>
<dd>如果数组中至少有一个元素满足测试函数,则返回 true否则返回 false。参照 <a href="Reference/Global_Objects/Array/some" title="some() 方法测试是否至少有一个元素通过由提供的函数实现的测试。"><code>Array.prototype.some()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/sort" title="sort()方法原地排序类型化数组的元素并且返回类型化数组。这个方法的算法和Array.prototype.sort()相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int8Array.prototype.sort()</code></a></dt>
<dd>对数组元素进行排序,并返回当前数组. 参照<a href="Reference/Global_Objects/Array/sort" title="sort() 方法用原地算法对数组的元素进行排序并返回数组。排序算法现在是稳定的。默认排序顺序是根据字符串Unicode码点。"><code>Array.prototype.sort()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/subarray" title="此页面仍未被本地化, 期待您的翻译!"><code>Int8Array.prototype.subarray()</code></a></dt>
<dd>返回一个以给定的初始结束位置裁剪的Int8Array数组.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/values" title="values()返回新的 Array Iterator 对象,包含数组中每个下标处的值。"><code>Int8Array.prototype.values()</code></a></dt>
<dd>返回一个数组迭代器对象,该迭代器会包含所有数组元素的值。. 参照 <a href="Reference/Global_Objects/Array/values" title="values() 方法返回一个新的 Array Iterator 对象该对象包含数组每个索引的值"><code>Array.prototype.values()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/toLocaleString" title="toLocaleString()方法返回一个字符串,表明该类型化数组的元素。这些元素被转化为字符串并由一个区域设置指定的分隔符(例如逗号 “,”分隔。这个方法与Array.prototype.toLocaleString()拥有相同的算法。同时由于类型化数组的元素都是数将每个元素转化为字符串的算法与Number.prototype.toLocaleString()是相同的。类型化数组的是typed array types中的其中一个。"><code>Int8Array.prototype.toLocaleString()</code></a></dt>
<dd>返回一个由所有数组元素组合而成的本地化后的字符串. See also <a href="Reference/Global_Objects/Array/toLocaleString" title='toLocaleString() 返回一个字符串表示数组中的元素。数组中的元素将使用各自的 toLocaleString 方法转成字符串,这些字符串将使用一个特定语言环境的字符串(例如一个逗号 ",")隔开。'><code>Array.prototype.toLocaleString()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/toString" title="toString()方法返回一个表示指定数组及其元素的字符串。这个方法的算法和Array.prototype.toString()一样。TypedArray 在这是typed array types 之一。"><code>Int8Array.prototype.toString()</code></a></dt>
<dd>返回一个由所有数组元素组合而成的字符串.参照 <a href="Reference/Global_Objects/Array/toString" title="toString() 返回一个字符串,表示指定的数组及其元素。"><code>Array.prototype.toString()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/@@iterator" title="@@iterator 的初始值是和 values 属性的初始值相同的对象。"><code>Int8Array.prototype[@@iterator]()</code></a></dt>
<dd>此方法返回一个带有数组内所有元素的迭代器对象同Int8Array.prototype.values </dd>
</dl>
<h2 id="示例">示例</h2>
<pre><code class="language-javascript">// 以长度参数构造对象
var int8 = new Int8Array(2);
int8[0] = 42;
console.log(int8[0]); // 42
console.log(int8.length); // 2
console.log(int8.BYTES_PER_ELEMENT); // 1
// 以数组构造对象
var arr = new Int8Array([21,31]);
console.log(arr[1]); // 31
// 从另一数组构造对象
var x = new Int8Array([21, 31]);
var y = new Int8Array(x);
console.log(y[0]); // 21
// 从ArrayBuffer构造对象
var buffer = new ArrayBuffer(8);
var z = new Int8Array(buffer, 1, 4);
</code></pre>
<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.khronos.org/registry/typedarray/specs/latest/" hreflang="en" lang="en" rel="noopener" title="Typed Array Specification">Typed Array Specification</a></td>
<td><span class="spec-Obsolete">Obsolete</span></td>
<td>已被 ECMAScript 6取代。</td>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#table-49" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">TypedArray constructors</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td>ECMA 标准中构造对象时 new 关键字为必需。</td>
</tr>
<tr>
<td><a class="external" href="https://tc39.github.io/ecma262/#table-49" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">TypedArray constructors</small></a></td>
<td><span class="spec-Draft">Draft</span></td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p></p><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
<div class="htab">
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
<ul>
<li class="selected"><a>Desktop</a></li>
<li><a>Mobile</a></li>
</ul>
</div><p></p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>功能</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>7.0</td>
<td><a href="/en-US/Firefox/Releases/4" title="Released on 2011-03-22.">4.0</a> (2)</td>
<td>10</td>
<td>11.6</td>
<td>5.1</td>
</tr>
<tr>
<td><code>new</code> is required</td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><a href="/en-US/Firefox/Releases/44" title="Released on 2016-01-26.">44</a> (44)</td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>4.0</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td>4.0 (2)</td>
<td>10</td>
<td>11.6</td>
<td>4.2</td>
</tr>
<tr>
<td><code>new</code> is required</td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td>44.0 (44)</td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
</tr>
</tbody>
</table>
</div>
<h2 id="兼容性说明">兼容性说明</h2>
<p>自 ECMAScript 2015 (ES6)施行, <code>Int8Array</code> 需要使用<a href="Reference/Operators/new" title="new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。"><code>new</code></a> 构造. 从当前版本开始不加new而便调用<code>Int8Array</code> 构造器方法, 将报出 <a href="Reference/Global_Objects/TypeError" title="TypeError类型错误 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a> 错误.</p>
<pre><code class="language-js example-bad">var dv = Int8Array([1, 2, 3]);
// TypeError: calling a builtin Int8Array constructor
// without new is forbidden</code></pre>
<pre><code class="language-js example-good">var dv = new Int8Array([1, 2, 3]);</code></pre>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="/en-US/docs/Web/JavaScript/Typed_arrays" title="en/JavaScript typed arrays">JavaScript typed arrays</a></li>
<li><a href="Reference/Global_Objects/ArrayBuffer" title="The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>ArrayBuffer</code></a></li>
<li><a href="Reference/Global_Objects/DataView" title="DataView 视图是一个可以从 ArrayBuffer 对象中读写多种数值类型的底层接口,在读写时不用考虑平台字节序问题。"><code>DataView</code></a></li>
</ul>
</article>