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

161 lines
12 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>
<h2 id="概要">概要</h2>
<p><strong><code>Uint32Array</code></strong>表示一个由基于平台字节序的32位无符号字节组成的数组.如果需要对字节顺序进行控制(译者注:即 littleEndian 或 bigEndian),请使用<a href="Reference/Global_Objects/DataView" title="DataView 视图是一个可以从 ArrayBuffer 对象中读写多种数值类型的底层接口,在读写时不用考虑平台字节序问题。"><code>DataView</code></a>代替.数组中每个元素的初始值都是0.一旦创建,你可以用对象的方法引用数组里的元素,或者使用标准的数组索引语法(即,使用中括号)。</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript">new Uint32Array(); // new in ES2017
new Uint32Array(length);
new Uint32Array(typedArray);
new Uint32Array(object);
new Uint32Array(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>Uint32Array.BYTES_PER_ELEMENT</code></a></dt>
<dd>返回一个number类型的值表示元素的size。 <code>Uint32Array 返回4。</code></dd>
<dt>Uint32Array.length</dt>
<dd>长度属性它的值是3。</dd>
<dt><a href="Reference/Global_Objects/TypedArray/name" title="TypedArray.name ?属性是描述类型数组构造名的字符串值。"><code>Uint32Array.name</code></a></dt>
<dd>返回字符串类型的值,表示构造器的名字。<code>Uint32Array</code> 的返回值是: "Uint32Array"。</dd>
<dt><a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>Uint32Array.prototype</code></a></dt>
<dd>返回 <em>TypedArray</em> 对象的原型链。</dd>
</dl>
<h2 id="方法">方法</h2>
<dl>
<dt>Uint32Array.from()</dt>
<dd>参考<a href="Reference/Global_Objects/Array/from" title="Array.from() 方法从一个类似数组或可迭代对象中创建一个新的数组实例。"><code>Array.from()</code></a>。 未完成,请参考<a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=896608" rel="noopener" title="FIXED: Implement ES6 %TypedArray%.{of, from}">bug 896608</a></dd>
<dt>Uint32Array.of()</dt>
<dd>参考<a href="Reference/Global_Objects/Array/of" title="Array.of() 方法创建一个具有可变数量参数的新数组实例,而不考虑参数的数量或类型。"><code>Array.of()</code></a>。未完成,请参考 <a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=896608" rel="noopener" title="FIXED: Implement ES6 %TypedArray%.{of, from}">bug 896608</a>.</dd>
</dl>
<h2 id="Boolean_instances" name="Boolean_instances"><code>Uint32Array</code> prototype</h2>
<p><code><font face="Open Sans, sans-serif">所有</font>Uint32Array</code> 对象继承自 <a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>%TypedArray%.prototype</code></a>.</p>
<h3 id="Properties">Properties</h3>
<dl>
<dt><code>Uint32Array.prototype.constructor</code></dt>
<dd>返回创建实例原型的函数。 默认返回 <code>Uint32Array</code> 的构造器。</dd>
<dt><a href="Reference/Global_Objects/TypedArray/buffer" title="buffer访问器属性表示由TypedArray在构造期间引用的ArrayBuffer。"><code>Uint32Array.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>Uint32Array</code> Fixed at construction time and thus <strong>read only</strong>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/byteLength" title="byteLength访问器属性表示类型化数组的长度字节数。"><code>Uint32Array.prototype.byteLength</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the length (in bytes) of the <code>Uint32Array</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>Uint32Array.prototype.byteOffset</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the offset (in bytes) of the <code>Uint32Array</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>Uint32Array.prototype.length</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>Returns the number of elements hold in the <code>Uint32Array</code>. Fixed at construction time and thus <strong>read only.</strong></dd>
</dl>
<h3 id="Methods">Methods</h3>
<dl>
<dt><a href="Reference/Global_Objects/TypedArray/copyWithin" title="copyWithin()方法将数组中的元素序列复制到以target起始的位置。 副本取自第二个参数和第三个参数 start 和end的位置下标。end 参数是可选的默认为数组长度。这个方法的算法和Array.prototype.copyWithin相同。 TypedArray 是这里的 类型化数组类型 之一。"><code>Uint32Array.prototype.copyWithin()</code></a></dt>
<dd>See <a href="Reference/Global_Objects/Array/copyWithin" title="改变了的数组。"><code>Array.prototype.copyWithin()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/move" title="move()方法将数组中的元素序列复制到以target起始的位置。但是这个非标准方法已经被TypedArray.prototype.copyWithin() 标准方法取代。TypedArray 是这里的 类型化数组类型 之一。"><code>Uint32Array.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>Uint32Array.prototype.copyWithin()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/set" title="set() 方法用于从指定数组中读取值,并将其存储在类型化数组中。"><code>Uint32Array.prototype.set()</code></a></dt>
<dd>Stores multiple values in the <code>Uint32Array</code>, reading input values from a specified array.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/subarray" title="此页面仍未被本地化, 期待您的翻译!"><code>Uint32Array.prototype.subarray()</code></a></dt>
<dd>Returns a new <code>Uint32Array</code> from the given start and end element index.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<pre><code class="language-javascript">// From a length
var uint32 = new Uint32Array(2);
uint32[0] = 42;
console.log(uint32[0]); // 42
console.log(uint32.length); // 2
console.log(uint32.BYTES_PER_ELEMENT); // 4
// From an array
var arr = new Uint32Array([21,31]);
console.log(arr[1]); // 31
// From another TypedArray
var x = new Uint32Array([21, 31]);
var y = new Uint32Array(x);
console.log(y[0]); // 21
// From an ArrayBuffer
var buffer = new ArrayBuffer(16);
var z = Uint32Array(buffer, 0, 4);
</code></pre>
<h2 id="Specifications">Specifications</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/#7" rel="noopener">Typed Array Specification</a></td>
<td>Obsolete</td>
<td><span><span>Superseded by ECMAScript 6.</span></span></td>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#table-45" 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.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</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>
</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>
</tbody>
</table>
</div>
<h2 id="See_also">See also</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>