ArrayBuffer()
constructor is used to create
ArrayBuffer
对象。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
new ArrayBuffer(length)
length
The size, in bytes, of the array buffer to create.
A new
ArrayBuffer
object of the specified size. Its contents are initialized to 0.
A
RangeError
is thrown if the
length
is larger than
Number.MAX_SAFE_INTEGER
(>= 2 ** 53) or negative.
Starting with ECMAScript 2015,
ArrayBuffer
constructors require to be constructed with a
new
operator. Calling an
ArrayBuffer
constructor as a function without
new
, will throw a
TypeError
from now on.
var dv = ArrayBuffer(10); // TypeError: calling a builtin ArrayBuffer constructor // without new is forbidden
var dv = new ArrayBuffer(10);
In this example, we create a 8-byte buffer with a
Int32Array
view referring to the buffer:
var buffer = new ArrayBuffer(8); var view = new Int32Array(buffer);
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'ArrayBuffer' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ArrayBuffer()
构造函数
|
Chrome 7 | Edge 12 | Firefox 4 | IE 10 | Opera 11.6 | Safari 5.1 | WebView Android 4 | Chrome Android 18 | Firefox Android 4 | Opera Android 12 | Safari iOS 4.2 | Samsung Internet Android 1.0 | nodejs 0.10 |
ArrayBuffer()
without
new
throws
|
Chrome 7 | Edge 14 | Firefox 44 | IE No | Opera 15 | Safari 5.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 44 | Opera Android 14 | Safari iOS 5 | Samsung Internet Android 1.0 | nodejs 0.12 |
完整支持
不支持
ArrayBuffer
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()