TypedArray.of()
TypedArray.of()
方法创建一个具有可变数量参数的新类型数组 。此方法几乎与Array.of()
相同。
句法
TypedArray.of(element0[, element1[, ...[, elementN]]])
where TypedArray is one of:
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
参数
elementN
- 创建类型数组的元素。
Return value
一个新的 TypedArray
实例。
描述
Array.of()
和 TypedArray.of()
之间的一些细微区别:
- 如果传递给 TypedArray.of 的这个值不是构造函数,TypedArray.of 将抛出一个
TypeError
,其中 Array.of 默认创建一个新的Array
。 TypedArray.of
使用 [[Put]] 其中 Array.of 使用 [[DefineProperty]]。因此,当使用Proxy
对象时,它调用handler.set
创建新的元素,而不是handler.defineProperty
。
范例
Uint8Array.of(1); // Uint8Array [ 1 ]
Int8Array.of("1", "2", "3"); // Int8Array [ 1, 2, 3 ]
Float32Array.of(1, 2, 3); // Float32Array [ 1, 2, 3 ]
Int16Array.of(undefined); // IntArray [ 0 ]
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) %TypedArray%.of |
Standard | Initial definition. |
ECMAScript (ECMA-262) %TypedArray%.of |
Living Standard |
浏览器兼容性
BCD tables only load in the browser