TypedArray.of()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

TypedArray.of()

는 가변적으로 인수를 전달 할수 있는 새로운 형식화 배열(typed array)를 만들어내는 메소드입니다.

이 메소드는 Array.of()와 거의 같습니다.

문법

TypedArray.of(element0[, element1[, ...[, elementN]]])

where TypedArray is one of:

  • Int8Array
  • Uint8Array
  • Uint8ClampedArray
  • Int16Array
  • Uint16Array
  • Int32Array
  • Uint32Array
  • Float32Array
  • Float64Array

매개변수

elementN

형식화 된 배열을 만들 요소입니다.

반환 값

생성된 TypedArray 인스턴스

설명

Array.of()TypedArray.of() 사이의 약간의 차이점은 다음과 같습니다.

  • TypedArray.of에 전달된 값이 생성자가 아닌 경우 TypedArray.ofTypeError를 발생시킵니다. Array.of는 기본적으로 새로운 Array를 생성합니다.
  • TypedArray.of uses [[Put]] where Array.of uses [[DefineProperty]]. Hence, when working with Proxy objects, it calls handler.set (en-US) to create new elements rather than handler.defineProperty (en-US).
  • TypedArray.ofArray.of[[DefineProperty]]를 사용하는 것처럼 [[Put]]을 사용합니다. 따라서 Proxy 객체로 작업 할 때 새로운 요소를 생성하기 위해 handler.set (en-US)대신 handler.defineProperty (en-US)를 호출합니다.

예제

js
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
ECMAScript Language Specification
# sec-%typedarray%.of

브라우저 호환성

BCD tables only load in the browser

See also