Uint8ClampedArray
(8位无符号整型固定数组) 类型化数组表示一个由值固定在0-255区间的8位无符号整型组成的数组;如果你指定一个在 [0,255] 区间外的值,它将被替换为0或255;如果你指定一个非整数,那么它将被设置为最接近它的整数。(数组)内容被初始化为0。一旦(数组)被创建,你可以使用对象的方法引用数组里的元素,或使用标准的数组索引语法(即使用方括号标记)。
new Uint8ClampedArray(length);
new Uint8ClampedArray(typedArray);
new Uint8ClampedArray(object);
new Uint8ClampedArray(buffer [, byteOffset [, length]]);
关于构造函数语法和参数的更多信息,参见 TypedArray。
Uint8ClampedArray.BYTES_PER_ELEMENT
Uint8ClampedArray
而言是1。Uint8ClampedArray.prototype.length
。Uint8ClampedArray.name
Uint8ClampedArray
类型而言:"Uint8ClampedArray"。Uint8ClampedArray.prototype
Uint8ClampedArray.from()
Uint8ClampedArray
。参见 Array.from()
。Uint8ClampedArray.of()
Uint8ClampedArray
。参见 Array.of()
。Uint8ClampedArray
原型所有的 Uint8ClampedArray
对象继承自 %TypedArray%.prototype
。
Uint8ClampedArray.prototype.constructor
Uint8ClampedArray
默认的构造函数。Uint8ClampedArray.prototype.buffer
只读 Uint8ClampedArray
引用的 ArrayBuffer
。在创建时所固定下来,因此只能读取。Uint8ClampedArray.prototype.byteLength
只读 ArrayBuffer
开始的 Uint8ClampedArray
的(字节的)长度。在创建时所固定下来,因此只能读取。Uint8ClampedArray.prototype.byteOffset
只读 ArrayBuffer
开始的 Uint8ClampedArray
的(字节的)偏移。在创建时所固定下来,因此只能读取。Uint8ClampedArray.prototype.length
只读 UintClamped8Array
具有的元素数量。在创建时所固定下来,因此只能读取。Uint8ClampedArray.prototype.copyWithin()
Array.prototype.copyWithin()
。Uint8ClampedArray.prototype.entries()
Array.prototype.entries()
。Uint8ClampedArray.prototype.every()
Array.prototype.every()
。Uint8ClampedArray.prototype.fill()
Array.prototype.fill()
。Uint8ClampedArray.prototype.filter()
Array.prototype.filter()
。Uint8ClampedArray.prototype.find()
undefined
。参见 Array.prototype.find()
。Uint8ClampedArray.prototype.findIndex()
Array.prototype.findIndex()
。Uint8ClampedArray.prototype.forEach()
Array.prototype.forEach()
。Uint8ClampedArray.prototype.includes()
true
或 false
。参见 Array.prototype.includes()
。Uint8ClampedArray.prototype.indexOf()
Array.prototype.indexOf()
.Uint8ClampedArray.prototype.join()
Array.prototype.join()
.Uint8ClampedArray.prototype.keys()
Array Iterator
that contains the keys for each index in the array. See also Array.prototype.keys()
.Uint8ClampedArray.prototype.lastIndexOf()
Array.prototype.lastIndexOf()
.Uint8ClampedArray.prototype.map()
Array.prototype.map()
.Uint8ClampedArray.prototype.move()
未实现Uint8ClampedArray.prototype.copyWithin()
.Uint8ClampedArray.prototype.reduce()
Array.prototype.reduce()
.Uint8ClampedArray.prototype.reduceRight()
Array.prototype.reduceRight()
.Uint8ClampedArray.prototype.reverse()
Array.prototype.reverse()
.Uint8ClampedArray.prototype.set()
Uint8ClampedArray.prototype.slice()
Array.prototype.slice()
.Uint8ClampedArray.prototype.some()
Array.prototype.some()
.Uint8ClampedArray.prototype.sort()
Array.prototype.sort()
.Uint8ClampedArray.prototype.subarray()
Uint8ClampedArray
from the given start and end element index.Uint8ClampedArray.prototype.values()
Array Iterator
object that contains the values for each index in the array. See also Array.prototype.values()
.Uint8ClampedArray.prototype.toLocaleString()
Array.prototype.toLocaleString()
.Uint8ClampedArray.prototype.toString()
Array.prototype.toString()
.Uint8ClampedArray.prototype[@@iterator]()
Array Iterator
object that contains the values for each index in the array.创建一个 Uint8ClampedArray
的不同方式:
// 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]
规范 | 状态 | 注释 |
---|---|---|
Typed Array Specification | Obsolete | 已由 ECMAScript 2015 替代。 |
ECMAScript 2015 (6th Edition, ECMA-262) TypedArray constructors |
Standard | 最初定义在一份 ECMA 标准中。规定 new 是必需的。 |
ECMAScript Latest Draft (ECMA-262) TypedArray constructors |
Draft |
特性 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
基础支持 | 7.0 | 4.0 (2) | 11 (as of KB2929437) | 11.6 | 5.1 |
需要使用 new |
? | 44 (44) | ? | ? | ? |
构造函数中可枚举 | ? | 52 (52) | ? | ? | ? |
特性 | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
基础支持 | 4.0 | (Yes) | 4.0 (2) | (Yes) | 11.6 | 4.2 |
需要使用 new |
? | ? | 44.0 (44) | ? | ? | ? |
构造函数中可枚举 | ? | ? | 52.0 (52) | ? | ? | ? |
从 ECMAScript 2015 开始, Uint8ClampedArray
构造函数需要用一个 new
操作符来构建。从现在开始,不使用 new
来调用一个 Uint8ClampedArray
构造函数将会抛出一个 TypeError
。
var dv = Uint8ClampedArray([1, 2, 3]);
// TypeError: calling a builtin Uint8ClampedArray constructor
// without new is forbidden
var dv = new Uint8ClampedArray([1, 2, 3]);