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

233 lines
30 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>The <strong><code>Int32Array</code></strong> 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 <a href="Reference/Global_Objects/DataView" title="DataView 视图是一个可以从 ArrayBuffer 对象中读写多种数值类型的底层接口,在读写时不用考虑平台字节序问题。"><code>DataView</code></a> instead. The contents are initialized to <code>0</code>. 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).</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript">new Int32Array(length);
new Int32Array(typedArray);
new Int32Array(object);
new Int32Array(buffer [, byteOffset [, length]]);</code></pre>
<p>For more information about the constructor syntax and the parameters, see <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>Int32Array.BYTES_PER_ELEMENT</code></a></dt>
<dd>Returns a number value of the element size. <code>4</code> in the case of an <code>Int32Array</code>.</dd>
<dt>Int32Array.length</dt>
<dd>Static length property whose value is 3. For the actual length (number of elements), see <a href="Reference/Global_Objects/TypedArray/length" title="length访问器属性表示类型化数组的长度元素数。"><code>Int32Array.prototype.length</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/name" title="TypedArray.name ?属性是描述类型数组构造名的字符串值。"><code>Int32Array.name</code></a></dt>
<dd>Returns the string value of the constructor name. In the case of the <code>Int32Array</code> type: "Int32Array".</dd>
<dt><a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>Int32Array.prototype</code></a></dt>
<dd>Prototype for the <em>TypedArray</em> objects.</dd>
</dl>
<h2 id="方法">方法</h2>
<dl>
<dt><a href="Reference/Global_Objects/TypedArray/from" title="TypedArray.from() 方法 从一个类数组或者可迭代对象中创建一个新类型数组。 这个方法和 Array.from()类似。"><code>Int32Array.from()</code></a></dt>
<dd>Creates a new <code>Int32Array</code> from an array-like or iterable object. See also <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>Int32Array.of()</code></a></dt>
<dd>Creates a new <code>Int32Array</code> with a variable number of arguments. See also <a href="Reference/Global_Objects/Array/of" title="Array.of() 方法创建一个具有可变数量参数的新数组实例,而不考虑参数的数量或类型。"><code>Array.of()</code></a>.</dd>
</dl>
<h2 id="Int32Array_属性"><code>Int32Array</code> 属性</h2>
<p>All <code>Int32Array</code> objects inherit from <a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>%TypedArray%.prototype</code></a>.</p>
<h3 id="属性_2">属性</h3>
<dl>
<dt><code>Int32Array.prototype.constructor</code></dt>
<dd>Returns the function that created an instance's prototype. This is the <code>Int32Array</code> constructor by default.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/buffer" title="buffer访问器属性表示由TypedArray在构造期间引用的ArrayBuffer。"><code>Int32Array.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>Int32Array</code> Fixed at construction time and thus <strong>read only</strong>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/byteLength" title="byteLength访问器属性表示类型化数组的长度字节数。"><code>Int32Array.prototype.byteLength</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the length (in bytes) of the <code>Int32Array</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>Int32Array.prototype.byteOffset</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the offset (in bytes) of the <code>Int32Array</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>Int32Array.prototype.length</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the number of elements hold in the <code>Int32Array</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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.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>Int32Array.prototype.map()</code></a></dt>
<dd>Creates a new array with the results of calling a provided function on every element in this array. 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>Int32Array.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>Former non-standard version of <a href="Reference/Global_Objects/TypedArray/copyWithin" title="copyWithin()方法将数组中的元素序列复制到以target起始的位置。 副本取自第二个参数和第三个参数 start 和end的位置下标。end 参数是可选的默认为数组长度。这个方法的算法和Array.prototype.copyWithin相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Int32Array.prototype.copyWithin()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/reduce" title="reduce() 方法接受一个函数作为参数,这个函数作为一个累加器,从左到右遍历整个类型数组,最后返回一个单一的值. 这个方法和Array.prototype.reduce()使用了同样的算法. TypedArray 是一个 类型数组."><code>Int32Array.prototype.reduce()</code></a></dt>
<dd>Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value. See also <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>Int32Array.prototype.reduceRight()</code></a></dt>
<dd>Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value. See also <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>Int32Array.prototype.reverse()</code></a></dt>
<dd>Reverses the order of the elements of an array — the first becomes the last, and the last becomes the first. See also <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>Int32Array.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>Int32Array.prototype.slice()</code></a></dt>
<dd>Extracts a section of an array and returns a new array. See also <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>Int32Array.prototype.some()</code></a></dt>
<dd>Returns true if at least one element in this array satisfies the provided testing function. See also <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>Int32Array.prototype.sort()</code></a></dt>
<dd>Sorts the elements of an array in place and returns the array. See also <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>Int32Array.prototype.subarray()</code></a></dt>
<dd>Returns a new <code>Int32Array</code> from the given start and end element index.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/values" title="values()返回新的 Array Iterator 对象,包含数组中每个下标处的值。"><code>Int32Array.prototype.values()</code></a></dt>
<dd>Returns a new <code>Array Iterator</code> object that contains the values for each index in the array. See also <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>Int32Array.prototype.toLocaleString()</code></a></dt>
<dd>Returns a localized string representing the array and its elements. 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>Int32Array.prototype.toString()</code></a></dt>
<dd>Returns a string representing the array and its elements. See also <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>Int32Array.prototype[@@iterator]()</code></a></dt>
<dd>Returns a new <code>Array Iterator</code> object that contains the values for each index in the array.</dd>
</dl>
<h2 id="例子">例子</h2>
<pre><code class="language-javascript">// From a length
var int32 = new Int32Array(2);
int32[0] = 42;
console.log(int32[0]); // 42
console.log(int32.length); // 2
console.log(int32.BYTES_PER_ELEMENT); // 4
// From an array
var arr = new Int32Array([21,31]);
console.log(arr[1]); // 31
// From another TypedArray
var x = new Int32Array([21, 31]);
var y = new Int32Array(x);
console.log(y[0]); // 21
// From an ArrayBuffer
var buffer = new ArrayBuffer(16);
var z = new Int32Array(buffer, 0, 4);
</code></pre>
<h2 id="详细描述">详细描述</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</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>Superseded by 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>Initial definition in an ECMA standard. Specified that <code>new</code> is required.</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>Feature</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>Starting with ECMAScript 2015 (ES6), <code>In32Array</code> constructors require to be constructed with a <a href="Reference/Operators/new" title="new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。"><code>new</code></a> operator. Calling a <code>Int32Array</code> constructor as a function without <code>new</code>, will throw a <a href="Reference/Global_Objects/TypeError" title="TypeError类型错误 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a> from now on.</p>
<pre><code class="language-js example-bad">var dv = Int32Array([1, 2, 3]);
// TypeError: calling a builtin Int32Array constructor
// without new is forbidden</code></pre>
<pre><code class="language-js example-good">var dv = new Int32Array([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>