ArrayBuffer

This translation is in progress.

ArrayBuffer 객체는 일반적인 고정 길이 원시 이진 데이터 버퍼를 나타냅니다.

ArrayBuffer에 담긴 정보를 직접 수정하는 것은 불가능하지만, 대신 타입이 있는 배열이나 특정 포맷의 버퍼를 나타내는 DataView를 생성하고 그것을 이용해 버퍼의 내용물을 읽고 쓸 수 있습니다.

구문

new ArrayBuffer(length)

매개변수

length
바이트 단위로 나타낸 버퍼에 저장된 길이.

반환 값

새로운 ArrayBuffer 객체가 지정된 길이로 만들어져 반환됩니다. 새 객체의 내용물은 0으로 초기화됩니다.

설명

ArrayBuffer 생성자는 바이트 단위의 길이가 주어지면 해당하는 길이의 ArrayBuffer 객체를 생성합니다.

기존 데이터에서 배열 버퍼 가져 오기

속성

ArrayBuffer.length
ArrayBuffer 생성자의 length 속성이며, 값은 1이다.
get ArrayBuffer[@@species]
파생된 객체들을 생성하는 데 사용되는 생성자 함수이다.
ArrayBuffer.prototype
모든 ArrayBuffer 객체에 속성을 추가할 수 있게 한다.

메서드

ArrayBuffer.isView(arg)
타입이 있는 배열이나 DataView처럼 arg가 ArrayBuffer의 view 중 하나라면 true를 반환하고, 아니라면 false를 반환한다.
ArrayBuffer.transfer(oldBuffer [, newByteLength])
oldBuffer의 데이터를 newByteLength를 바탕으로 축약(Truncate)하거나 0을 추가한 ArrayBuffer를 반환한다.

인스턴스

ArrayBuffer 의 모든 인스턴스들은 ArrayBuffer.prototype 를 통해 상속받는다.

Properties

ArrayBuffer.length
The ArrayBuffer constructor's length property whose value is 1.
get ArrayBuffer[@@species]
The constructor function that is used to create derived objects.
ArrayBuffer.prototype
Allows the addition of properties to all ArrayBuffer objects.

Methods

ArrayBuffer.isView(arg)
Returns true if arg is one of the ArrayBuffer views, such as typed array objects or a DataView. Returns false otherwise.
ArrayBuffer.transfer(oldBuffer [, newByteLength])
Returns a new ArrayBuffer whose contents are taken from the oldBuffer's data and then is either truncated or zero-extended by newByteLength.
ArrayBuffer.slice()
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

브라우저 호환성

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
ArrayBufferChrome Full support 7Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 11.6Safari Full support 5.1WebView Android Full support 4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support Yes
ArrayBuffer() constructorChrome Full support 7Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 11.6Safari Full support 5.1WebView Android Full support 4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support Yes
byteLengthChrome Full support 7Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 11.6Safari Full support 5.1WebView Android Full support 4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support Yes
isViewChrome Full support 32Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 19Safari Full support 7WebView Android Full support ≤37Chrome Android Full support 32Firefox Android Full support 29Opera Android Full support 19Safari iOS Full support 7Samsung Internet Android Full support 2.0nodejs Full support Yes
ArrayBuffer() without new throwsChrome Full support 7Edge Full support 14Firefox Full support 44IE No support NoOpera Full support 15Safari Full support 5.1WebView Android Full support ≤37Chrome Android Full support 18Firefox Android Full support 44Opera Android Full support 14Safari iOS Full support 5Samsung Internet Android Full support 1.0nodejs Full support 0.12
sliceChrome Full support 17Edge Full support 12Firefox Full support 12
Notes
Full support 12
Notes
Notes The non-standard ArrayBuffer.slice() method has been removed in Firefox 53 (but the standardized version ArrayBuffer.prototype.slice() is kept.
IE Full support 11Opera Full support 12.1Safari Full support 6WebView Android Full support ≤37Chrome Android Full support 18Firefox Android Full support 14
Notes
Full support 14
Notes
Notes The non-standard ArrayBuffer.slice() method has been removed in Firefox 53 (but the standardized version ArrayBuffer.prototype.slice() is kept.
Opera Android Full support 12.1Safari iOS Full support 6Samsung Internet Android Full support 1.0nodejs Full support Yes
@@speciesChrome Full support 51Edge Full support 13Firefox Full support 48IE No support NoOpera Full support 38Safari Full support 10WebView Android Full support 51Chrome Android Full support 51Firefox Android Full support 48Opera Android Full support 41Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.5.0
Full support 6.5.0
Full support 6.0.0
Disabled
Disabled From version 6.0.0: this feature is behind the --harmony runtime flag.

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

호환성 참고사항

ECMAScript 2015 부터, ArrayBuffer 생성자는 new 연산자를 통해 생성되어야 한다. 이제부터는 ArrayBuffer 생성자 함수를 new 없이 호출할 경우, TypeError 에러가 발생한다.

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

같이 보기