mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-08 23:14:06 +08:00
234 lines
29 KiB
HTML
234 lines
29 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<p><strong><code>Float32Array</code></strong> 类型数组代表的是平台字节顺序为32位的浮点数型数组(对应于 C 浮点数据类型) 。 如果需要控制字节顺序, 使用 <a href="Reference/Global_Objects/DataView" title="DataView 视图是一个可以从 ArrayBuffer 对象中读写多种数值类型的底层接口,在读写时不用考虑平台字节序问题。"><code>DataView</code></a> 替代。其内容初始化为<code>0</code>。一旦建立起来,你可以使用这个对象的方法对其元素进行操作,或者使用标准数组索引语法 (使用方括号)。</p>
|
||
<h2 id="语法">语法</h2>
|
||
<pre><code class="language-javascript">new Float32Array(length);
|
||
new Float32Array(typedArray);
|
||
new Float32Array(object);
|
||
new Float32Array(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>Float32Array.BYTES_PER_ELEMENT</code></a></dt>
|
||
<dd>返回元素字节数。 <code>在</code> <code>Float32Array的情况下返回4。</code></dd>
|
||
<dt>Float32Array.length</dt>
|
||
<dd>长度属性的值为 3。关于其实际长度(元素数量)参见<a href="Reference/Global_Objects/TypedArray/length" title="length访问器属性表示类型化数组的长度(元素数)。"><code>Float32Array.prototype.length</code></a>。</dd>
|
||
<dt><a href="Reference/Global_Objects/TypedArray/name" title="TypedArray.name ?属性是描述类型数组构造名的字符串值。"><code>Float32Array.name</code></a></dt>
|
||
<dd>返回构造函数名字的字符串值。在 <code>Float32Array</code> 类型的情况下为:"Float32Array"。</dd>
|
||
<dt><a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>Float32Array.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>Float32Array.from()</code></a></dt>
|
||
<dd>从一个类数组对象或可遍历对象创建一个新的Float32Array。参见 <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>Float32Array.of()</code></a></dt>
|
||
<dd>用可变数量的参数创建一个新的Float32Array。 参见 <a href="Reference/Global_Objects/Array/of" title="Array.of() 方法创建一个具有可变数量参数的新数组实例,而不考虑参数的数量或类型。"><code>Array.of()</code></a>。</dd>
|
||
</dl>
|
||
<h2 id="Boolean_instances" name="Boolean_instances"><code>Float32Array</code> 属性</h2>
|
||
<p>所有的<code>Float32Array对象都</code>继承自 <a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>%TypedArray%.prototype</code></a>。</p>
|
||
<h3 id="特性">特性</h3>
|
||
<dl>
|
||
<dt><code>Float32Array.prototype.constructor</code></dt>
|
||
<dd>返回创建这个实例原型的函数。 这是<code>Float32Array</code> 默认的构造函数。</dd>
|
||
<dt><a href="Reference/Global_Objects/TypedArray/buffer" title="buffer访问器属性表示由TypedArray在构造期间引用的ArrayBuffer。"><code>Float32Array.prototype.buffer</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
|
||
<dd>返回这个<code>Float32Array引用的</code><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>。构造时已固定,所以是<strong>只读</strong>的。</dd>
|
||
<dt><a href="Reference/Global_Objects/TypedArray/byteLength" title="byteLength访问器属性表示类型化数组的长度(字节数)。"><code>Float32Array.prototype.byteLength</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
|
||
<dd>返回从<code>Float32Array的</code><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>开头开始<code>的</code>长度 (以字节为单位) 。构造时已固定,所以是<strong>只读</strong>的。</dd>
|
||
<dt><a href="Reference/Global_Objects/TypedArray/byteOffset" title="byteOffset 访问器属性表示类型化数组距离其ArrayBuffer起始位置的偏移(字节数)。"><code>Float32Array.prototype.byteOffset</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
|
||
<dd>返回从<code>Float32Array的</code><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>开头开始<code>的偏移量</code> (以字节为单位) 。构造时已固定,所以是<strong>只读</strong>的。</dd>
|
||
<dt><a href="Reference/Global_Objects/TypedArray/length" title="length访问器属性表示类型化数组的长度(元素数)。"><code>Float32Array.prototype.length</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
|
||
<dd>返回<code>Float32Array中的元素个数</code>。构造时已固定,所以是<strong>只读</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>Float32Array.prototype.copyWithin()</code></a></dt>
|
||
<dd>从数组复制元素。参见<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>Float32Array.prototype.entries()</code></a></dt>
|
||
<dd><code>返回一个包含数组中每个元素键值对的数组遍历器对象</code>。参见<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>Float32Array.prototype.every()</code></a></dt>
|
||
<dd>检测是否所有元素都能通过给定函数的测试。参见<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>Float32Array.prototype.fill()</code></a></dt>
|
||
<dd>用一个静态值填充给定的起始位置。 参见<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>Float32Array.prototype.filter()</code></a></dt>
|
||
<dd>创建一个新数组,数据为原数组中所有能让给入函数返回true的元素。参见<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>Float32Array.prototype.find()</code></a></dt>
|
||
<dd>返回满足测试函数的值,如果没有找到,返回undefined。 参见<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>Float32Array.prototype.findIndex()</code></a></dt>
|
||
<dd>返回满足测试函数的值的位置,如果没有找到,返回-1。参见<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>Float32Array.prototype.forEach()</code></a></dt>
|
||
<dd>以每个元素为参数各调用一次函数。参见<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>Float32Array.prototype.includes()</code></a> <span title="这是一个实验性的 API,请尽量不要在生产环境中使用它。"><i class="icon-beaker"> </i></span></dt>
|
||
<dd>判断是否包含某个元素,<code>返回true</code> 或 <code>false</code>。参见<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>Float32Array.prototype.indexOf()</code></a></dt>
|
||
<dd>返回数组中等于给定值的元素的第一个(最小)位置, 没有找到则返回-1。参见<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>Float32Array.prototype.join()</code></a></dt>
|
||
<dd>合并所有数组元素到一个字符串中。 参见<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>Float32Array.prototype.keys()</code></a></dt>
|
||
<dd><code>返回一个包含数组中所有索引的数组遍历器</code>。 参见<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>Float32Array.prototype.lastIndexOf()</code></a></dt>
|
||
<dd>返回数组中等于给定值的元素的最后(最大)位置, 没有找到则返回-1。参见<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>Float32Array.prototype.map()</code></a></dt>
|
||
<dd>创建一个新的数组,数据由原数组每个元素依次传入给定函数后返回的值组成。参见<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>Float32Array.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>Float32Array.prototype.copyWithin()</code></a>以前的一个非标准版本。</dd>
|
||
<dt><a href="Reference/Global_Objects/TypedArray/reduce" title="reduce() 方法接受一个函数作为参数,这个函数作为一个累加器,从左到右遍历整个类型数组,最后返回一个单一的值. 这个方法和Array.prototype.reduce()使用了同样的算法. TypedArray 是一个 类型数组."><code>Float32Array.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>Float32Array.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>Float32Array.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>Float32Array.prototype.set()</code></a></dt>
|
||
<dd>从给定的数组存入多个数值。</dd>
|
||
<dt><a href="Reference/Global_Objects/TypedArray/slice" title="slice()方法返回一个typed array的部分类型数组对象,数组内容采用浅拷贝方式. 方法采用与 Array.prototype.slice()相同的算法. 类型数组是 typed array types成员中的一员 ."><code>Float32Array.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>Float32Array.prototype.some()</code></a></dt>
|
||
<dd>如果数组中至少有一个元素满足测试函数的要求则返回true。参见<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>Float32Array.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>Float32Array.prototype.subarray()</code></a></dt>
|
||
<dd>从给定的起始位置返回一个新的<code>Float32Array</code> 。</dd>
|
||
<dt><a href="Reference/Global_Objects/TypedArray/values" title="values()返回新的 Array Iterator 对象,包含数组中每个下标处的值。"><code>Float32Array.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>Float32Array.prototype.toLocaleString()</code></a></dt>
|
||
<dd>返回一个代表数组和其元素的本地化格式字符串。参见<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>Float32Array.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>Float32Array.prototype[@@iterator]()</code></a></dt>
|
||
<dd>返回一个新的包含数组元素的数组迭代器对象。</dd>
|
||
</dl>
|
||
<h2 id="例子">例子</h2>
|
||
<pre><code class="language-javascript">// From a length
|
||
var float32 = new Float32Array(2);
|
||
float32[0] = 42;
|
||
console.log(float32[0]); // 42
|
||
console.log(float32.length); // 2
|
||
console.log(float32.BYTES_PER_ELEMENT); // 4
|
||
|
||
// From an array
|
||
var arr = new Float32Array([21,31]);
|
||
console.log(arr[1]); // 31
|
||
|
||
// From another TypedArray
|
||
var x = new Float32Array([21, 31]);
|
||
var y = new Float32Array(x);
|
||
console.log(y[0]); // 21
|
||
|
||
// From an ArrayBuffer
|
||
var buffer = new ArrayBuffer(16);
|
||
var z = new Float32Array(buffer, 0, 4);
|
||
</code></pre>
|
||
<h2 id="sect1"> </h2>
|
||
<h2 id="规范">规范</h2>
|
||
<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>基础支持</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></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>特性</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>基础支持</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></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>Float32Array</code>构造函数需要用一个<a href="Reference/Operators/new" title="new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。"><code>new</code></a>操作符来构造。现在直接把<code>Float32Array构造函数当函数调用而不使用new,会抛出一个</code><a href="Reference/Global_Objects/TypeError" title="TypeError(类型错误) 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a>。</p>
|
||
<pre><code class="language-js example-bad">var dv = Float32Array([1, 2, 3]);
|
||
// TypeError: calling a builtin Float32Array constructor
|
||
// 不允许不使用new</code></pre>
|
||
<pre><code class="language-js example-good">var dv = new Float32Array([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> |