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

258 lines
31 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>Uint8ClampedArray</code>8位无符号整型固定数组</strong> 类型化数组表示一个由值固定在0-255区间的8位无符号整型组成的数组如果你指定一个在 [0,255] 区间外的值它将被替换为0或255如果你指定一个非整数那么它将被设置为最接近它的整数。数组内容被初始化为0。一旦数组被创建你可以使用对象的方法引用数组里的元素或使用标准的数组索引语法即使用方括号标记</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript">new Uint8ClampedArray(length);
new Uint8ClampedArray(typedArray);
new Uint8ClampedArray(object);
new Uint8ClampedArray(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>Uint8ClampedArray.BYTES_PER_ELEMENT</code></a></dt>
<dd>返回元素大小的一个数值。对 <code>Uint8ClampedArray</code> 而言是1。</dd>
<dt>Uint8ClampedArray.length</dt>
<dd>静态长度属性值为0。对于实际长度元素的数量<a href="Reference/Global_Objects/TypedArray/length" title="length访问器属性表示类型化数组的长度元素数。"><code>Uint8ClampedArray.prototype.length</code></a></dd>
<dt><a href="Reference/Global_Objects/TypedArray/name" title="TypedArray.name ?属性是描述类型数组构造名的字符串值。"><code>Uint8ClampedArray.name</code></a></dt>
<dd>返回构造函数名的字符串值。对 <code>Uint8ClampedArray</code> 类型而言:"Uint8ClampedArray"。</dd>
<dt><a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>Uint8ClampedArray.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>Uint8ClampedArray.from()</code></a></dt>
<dd>从一个类数组或可枚举对象创建一个新的 <code>Uint8ClampedArray</code>。参见 <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>Uint8ClampedArray.of()</code></a></dt>
<dd>通过一个可选数量参数来创建一个新的 <code>Uint8ClampedArray</code>。参见 <a href="Reference/Global_Objects/Array/of" title="Array.of() 方法创建一个具有可变数量参数的新数组实例,而不考虑参数的数量或类型。"><code>Array.of()</code></a></dd>
</dl>
<h2 id="Uint8ClampedArray_原型"><code>Uint8ClampedArray</code> 原型</h2>
<p>所有的 <code>Uint8ClampedArray</code> 对象继承自 <a href="Reference/Global_Objects/TypedArray/prototype" title="TypedArray.prototype属性表示TypedArray构造器的原型."><code>%TypedArray%.prototype</code></a></p>
<h3 id="属性_2">属性</h3>
<dl>
<dt><code>Uint8ClampedArray.prototype.constructor</code></dt>
<dd>返回创建一个实例原型的函数。这是 <code>Uint8ClampedArray</code> 默认的构造函数。</dd>
<dt><a href="Reference/Global_Objects/TypedArray/buffer" title="buffer访问器属性表示由TypedArray在构造期间引用的ArrayBuffer。"><code>Uint8ClampedArray.prototype.buffer</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>返回由 <code>Uint8ClampedArray</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>Uint8ClampedArray.prototype.byteLength</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>返回从 <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>Uint8ClampedArray</code> 的(字节的)长度。在创建时所固定下来,因此<strong>只能读取</strong></dd>
<dt><a href="Reference/Global_Objects/TypedArray/byteOffset" title="byteOffset 访问器属性表示类型化数组距离其ArrayBuffer起始位置的偏移字节数。"><code>Uint8ClampedArray.prototype.byteOffset</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>返回从 <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>Uint8ClampedArray</code> 的(字节的)偏移。在创建时所固定下来,因此<strong>只能读取</strong></dd>
<dt><a href="Reference/Global_Objects/TypedArray/length" title="length访问器属性表示类型化数组的长度元素数。"><code>Uint8ClampedArray.prototype.length</code></a> <span class="inlineIndicator readOnly readOnlyInline" title="该属性的值无法更改">只读 </span></dt>
<dd>返回 <code>UintClamped8Array</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>Uint8ClampedArray.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>Uint8ClampedArray.prototype.entries()</code></a></dt>
<dd>返回一个新的包含数组中每个索引对应的键/值对的数组迭代器对象。参见 <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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.prototype.find()</code></a></dt>
<dd>如果数组里的一个元素符合所提供的测试函数则返回找到的这个值,如果没有找到则返回 <code>undefined</code>。参见 <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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.prototype.copyWithin()</code></a>.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/reduce" title="reduce() 方法接受一个函数作为参数,这个函数作为一个累加器,从左到右遍历整个类型数组,最后返回一个单一的值. 这个方法和Array.prototype.reduce()使用了同样的算法. TypedArray 是一个 类型数组."><code>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.prototype.subarray()</code></a></dt>
<dd>Returns a new <code>Uint8ClampedArray</code> from the given start and end element index.</dd>
<dt><a href="Reference/Global_Objects/TypedArray/values" title="values()返回新的 Array Iterator 对象,包含数组中每个下标处的值。"><code>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>Uint8ClampedArray.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>
<p>创建一个 <code>Uint8ClampedArray</code> 的不同方式:</p>
<pre><code class="language-javascript">// From a length
var uintc8 = new Uint8ClampedArray(2);
uintc8[0] = 42;
uintc8[1] = 1337;
console.log(uintc8[0]); // 42
console.log(uintc8[1]); // 255 (clamped)
console.log(uintc8.length); // 2
console.log(uintc8.BYTES_PER_ELEMENT); // 1
// From an array
var arr = new Uint8ClampedArray([21,31]);
console.log(arr[1]); // 31
// From another TypedArray
var x = new Uint8ClampedArray([21, 31]);
var y = new Uint8ClampedArray(x);
console.log(y[0]); // 21
// From an ArrayBuffer
var buffer = new ArrayBuffer(8);
var z = new Uint8ClampedArray(buffer, 1, 4);
// From an iterable
var iterable = function*(){ yield* [1,2,3]; }();
var uintc8 = new Uint8ClampedArray(iterable);
// Uint8ClampedArray[1, 2, 3]
</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 2015 替代。</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 标准中。规定 <code>new</code> 是必需的。</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>11 (as of <a class="external" href="https://support.microsoft.com/en-us/kb/2929437" rel="noopener">KB2929437</a>)</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>
<tr>
<td>构造函数中可枚举</td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><a href="/en-US/Firefox/Releases/52" title="Released on 2017-03-07.">52</a> (52)</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><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></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>
<tr>
<td>构造函数中可枚举</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>52.0 (52)</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 开始, <code>Uint8ClampedArray</code> 构造函数需要用一个 <a href="Reference/Operators/new" title="new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。"><code>new</code></a> 操作符来构建。从现在开始,不使用 <code>new</code> 来调用一个 <code>Uint8ClampedArray</code> 构造函数将会抛出一个 <a href="Reference/Global_Objects/TypeError" title="TypeError类型错误 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a></p>
<pre><code class="language-js example-bad">var dv = Uint8ClampedArray([1, 2, 3]);
// TypeError: calling a builtin Uint8ClampedArray constructor
// without new is forbidden</code></pre>
<pre><code class="language-js example-good">var dv = new Uint8ClampedArray([1, 2, 3]);</code></pre>
<h2 id="参见">参见</h2>
<ul>
<li><a href="/en-US/docs/Web/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>