TypedArray.prototype.buffer

Baseline Widely available

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

buffer 접근자 속성은 생성 시 TypedArray에서 참조하는 ArrayBuffer를 나타냅니다.

시도해보기

설명

buffer 속성은 set 접근자 함수가 undefined인 속성으로, 이 속성은 읽을수만 있습니다. 값은 TypedArray가 생성될 때 설정되어 변경할 수 없습니다. TypedArrayTypedArray 객체 중 하나입니다.

예제

buffer 속성 사용하기

js
const buffer = new ArrayBuffer(8);
const uint16 = new Uint16Array(buffer);
uint16.buffer; // ArrayBuffer { byteLength: 8 }

잘린 배열 보기에서 기반 버퍼에 액세스하기

js
const buffer = new ArrayBuffer(1024);
const arr = new Uint8Array(buffer, 64, 128);
console.log(arr.byteLength); // 128
console.log(arr.buffer.byteLength); // 1024
console.log(arr.buffer === buffer); // true

명세서

Specification
ECMAScript Language Specification
# sec-get-%typedarray%.prototype.buffer

브라우저 호환성

BCD tables only load in the browser

같이 보기