You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!
ArrayBuffer
객체는 일반적이 길이가 정해진 원시 이진 데이터 버퍼를 나타내는 데 쓰입니다. ArrayBuffer
에 담긴 정보를 직접 수정하는 것은 불가능하지만, 대신 타입이 있는 배열이나 특정 포맷의 버퍼를 나타내는 DataView
를 생성하고 그것을 이용해 버퍼의 내용물을 읽고 쓸 수 있습니다.
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
- 바이트 단위로 나타낸 버퍼에 저장된 길이.
반환 값
새로운 ArrayBuffer
객체가 지정된 길이로 만들어져 반환됩니다. 새 객체의 내용물은 0으로 초기화됩니다.
설명
ArrayBuffer
생성자는 바이트 단위의 길이가 주어지면 해당하는 길이의 ArrayBuffer
객체를 생성합니다.
기존 데이터에서 배열 버퍼 가져 오기
속성
- ArrayBuffer.length
ArrayBuffer
생성자의 length 속성이며, 값은 1이다.get ArrayBuffer[@@species]
- The constructor function that is used to create derived objects.
ArrayBuffer.prototype
- 모든
ArrayBuffer
객체에 속성을 추가할 수 있게 한다.
메서드
ArrayBuffer.isView(arg)
- 타입이 있는 배열이나
DataView
처럼arg
가 ArrayBuffer의 view 중 하나라면true
를 반환하고, 아니라면false
를 반환한다. ArrayBuffer.transfer(oldBuffer [, newByteLength])
-
Returns a new
ArrayBuffer
whose contents are taken from theoldBuffer
's data and then is either truncated or zero-extended bynewByteLength
.
인스턴스
ArrayBuffer
의 모든 인스턴스들은 ArrayBuffer.prototype
를 통해 상속받는다.
Properties
- ArrayBuffer.prototype.constructor
- Specifies the function that creates an object's prototype. The initial value is the standard built-in
ArrayBuffer
constructor. ArrayBuffer.prototype.byteLength
Read only- The size, in bytes, of the array. This is established when the array is constructed and cannot be changed. Read only.
Methods
ArrayBuffer.prototype.slice()
- Returns a new
ArrayBuffer
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.
ArrayBuffer.slice()
- Has the same functionality as
ArrayBuffer.prototype.slice()
.
예제
이 예제에서는 8 바이트 크기의 버퍼를 생성하고 이를 Int32Array
에 참조시켰습니다.
var buffer = new ArrayBuffer(8); var view = new Int32Array(buffer);
명세
Specification | Status | Comment |
---|---|---|
Typed Array Specification | Obsolete | Superseded by ECMAScript 6. |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'ArrayBuffer' in that specification. |
Standard | Initial definition in an ECMA standard. Specified that new is required. |
ECMAScript Latest Draft (ECMA-262) The definition of 'ArrayBuffer' in that specification. |
Draft |
브라우저 호환성
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ArrayBuffer | Chrome Full support 7 | Edge Full support 12 | Firefox Full support 4 | IE Full support 10 | Opera Full support 11.6 | Safari Full support 5.1 | WebView Android Full support 4 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes | nodejs Full support Yes |
byteLength | Chrome Full support 7 | Edge Full support 12 | Firefox Full support 4 | IE Full support 10 | Opera Full support 11.6 | Safari Full support 5.1 | WebView Android Full support 4 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes | nodejs Full support Yes |
isView | Chrome Full support 32 | Edge Full support 12 | Firefox Full support 29 | IE Full support 11 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support ≤37 | Chrome Android Full support 32 | Firefox Android Full support 29 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 2.0 | nodejs Full support Yes |
ArrayBuffer() without new throws | Chrome Full support 7 | Edge Full support 14 | Firefox Full support 44 | IE No support No | Opera Full support Yes | Safari Full support 5.1 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 44 | Opera Android Full support Yes | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 | nodejs Full support 0.12 |
prototype | Chrome Full support 7 | Edge Full support 12 | Firefox Full support 4 | IE Full support 10 | Opera Full support 11.6 | Safari Full support 5.1 | WebView Android Full support 4 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes | nodejs Full support Yes |
slice | Chrome Full support 17 | Edge Full support 12 | Firefox
Full support
12
| IE Full support 11 | Opera Full support Yes | Safari Full support 6 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android
Full support
14
| Opera Android Full support Yes | Safari iOS Full support 6 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
transfer | Chrome No support No | Edge No support No | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
@@species | Chrome Full support 51 | Edge Full support 13 | Firefox Full support 48 | IE No support No | Opera Full support 38 | Safari ? | WebView Android Full support 51 | Chrome Android Full support 51 | Firefox Android Full support 48 | Opera Android Full support 41 | Safari iOS ? | Samsung Internet Android Full support 5.0 | nodejs
Full support
6.5.0
|
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.
호환성 참고사항
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);