TypedArray.prototype.buffer

buffer アクセサープロパティは、構築時に TypedArray から参照されるようになった ArrayBuffer を表します。

試してみましょう

解説

byteLength プロパティは設定アクセサープロパティが undefined である、読み取り専用のアクセサープロパティです。値は TypedArray が構築されたときに確立し、変更することができません。 TypedArray型付き配列オブジェクトのうちの一つです。

型付き配列はバッファーのビューであるため、基盤となるバッファーは型付き配列自体よりも長い場合があります。

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

関連情報