--- title: ArrayBuffer slug: Web/JavaScript/Reference/Global_Objects/ArrayBuffer translation_of: Web/JavaScript/Reference/Global_Objects/ArrayBuffer ---
{{JSRef}}
ArrayBuffer 物件是一種表示通用、固定大小的原始二進制資料緩衝。想要直接操作一個 ArrayBuffer 物件的內容是不可能的。若要讀寫該緩衝的內容則必須透過視圖,可以選擇建立一個 {{jsxref("DataView")}} 視圖物件或是一個限定其成員為某種型別的 {{jsxref("TypedArray")}} 視圖物件,它們皆能以特定的型別解讀、修改 ArrayBuffer。
new ArrayBuffer(length)
length為一個新建立的指定大小 ArrayBuffer 物件,其內容皆初始化為 0。
A {{jsxref("RangeError")}} is thrown if the length is larger than {{jsxref("Number.MAX_SAFE_INTEGER")}} (>= 2 ** 53) or negative.
The ArrayBuffer constructor creates a new ArrayBuffer of the given length in bytes.
ArrayBuffer.lengthArrayBuffer constructor's length property whose value is 1.ArrayBuffer objects.true if arg is one of the ArrayBuffer views, such as typed array objects or a {{jsxref("DataView")}}. Returns false otherwise.ArrayBuffer whose contents are taken from the oldBuffer's data and then is either truncated or zero-extended by newByteLength.ArrayBuffer 實例所有的 ArrayBuffer 物件實例皆繼承自 {{jsxref("ArrayBuffer.prototype")}}.
{{page('zh-TW/Web/JavaScript/JavaScript_typed_arrays/ArrayBuffer/prototype','屬性')}}
{{page('/zh-TW/docs/Web/JavaScript/JavaScript_typed_arrays/ArrayBuffer/prototype','方法')}}
In this example, we create a 8-byte buffer with a {{jsxref("Global_Objects/Int32Array", "Int32Array")}} view referring to the buffer:
var buffer = new ArrayBuffer(8); var view = new Int32Array(buffer);
Starting with ECMAScript 2015, ArrayBuffer constructors require to be constructed with a {{jsxref("Operators/new", "new")}} operator. Calling an ArrayBuffer constructor as a function without new, will throw a {{jsxref("TypeError")}} from now on.
var dv = ArrayBuffer(10); // TypeError: calling a builtin ArrayBuffer constructor // without new is forbidden
var dv = new ArrayBuffer(10);