Movatterモバイル変換


[0]ホーム

URL:


  1. 給開發者的 Web 技術文件
  2. JavaScript
  3. JavaScript 參考文件
  4. 標準內建物件
  5. ArrayBuffer

此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in EnglishAlways switch to English

ArrayBuffer

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

* Some parts of this feature may have varying levels of support.

ArrayBuffer 物件是一種表示通用、固定大小的原始二進制資料緩衝。想要直接操作一個ArrayBuffer 物件的內容是不可能的。若要讀寫該緩衝的內容則必須透過視圖,可以選擇建立一個DataView 視圖物件或是一個限定其成員為某種型別的TypedArray 視圖物件,它們皆能以特定的型別解讀、修改ArrayBuffer

語法

js
new ArrayBuffer(length)

參數

length

要建立的緩衝陣列大小,以位元組(byte)計算。

回傳值

為一個新建立的指定大小ArrayBuffer 物件,其內容皆初始化為 0。

Exceptions

ARangeError is thrown if thelength is larger thanNumber.MAX_SAFE_INTEGER (>= 2 ** 53) or negative.

說明

TheArrayBuffer constructor creates a newArrayBuffer of the given length in bytes.

從既有的資料取得 ArrayBuffer

屬性

ArrayBuffer.length

TheArrayBuffer constructor's length property whose value is 1.

ArrayBuffer[Symbol.species]

The constructor function that is used to create derived objects.

ArrayBuffer.prototype

Allows the addition of properties to allArrayBuffer objects.

方法

ArrayBuffer.isView(arg)

Returnstrue ifarg is one of the ArrayBuffer views, such astyped array objects or aDataView. Returnsfalse otherwise.

ArrayBuffer.transfer(oldBuffer [, newByteLength])實驗性質

Returns a newArrayBuffer whose contents are taken from theoldBuffer's data and then is either truncated or zero-extended bynewByteLength.

ArrayBuffer 實例

所有的ArrayBuffer 物件實例皆繼承自ArrayBuffer.prototype.

屬性

ArrayBuffer.prototype[Symbol.toStringTag]

The initial value of theSymbol.toStringTag property is the string"ArrayBuffer". This property is used inObject.prototype.toString().

ArrayBuffer.prototype.byteLength

The read-only size, in bytes, of theArrayBuffer. This is established when the array is constructed and cannot be changed.

方法

ArrayBuffer.prototype.slice()

Returns a newArrayBuffer whose contents are a copy of thisArrayBuffer's bytes frombegin (inclusive) up toend (exclusive). If eitherbegin orend is negative, it refers to an index from the end of the array, as opposed to from the beginning.

範例

In this example, we create a 8-byte buffer with aInt32Array view referring to the buffer:

js
var buffer = new ArrayBuffer(8);var view = new Int32Array(buffer);

規範

Specification
ECMAScript® 2026 Language Specification
# sec-arraybuffer-objects

瀏覽器相容性

相容性備註

Starting with ECMAScript 2015,ArrayBuffer constructors require to be constructed with anew operator. Calling anArrayBuffer constructor as a function withoutnew, will throw aTypeError from now on.

js
var dv = ArrayBuffer(10);// TypeError: calling a builtin ArrayBuffer constructor// without new is forbidden
js
var dv = new ArrayBuffer(10);

參見

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp