From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../global_objects/arraybuffer/index.html | 148 +++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 files/pt-br/web/javascript/reference/global_objects/arraybuffer/index.html (limited to 'files/pt-br/web/javascript/reference/global_objects/arraybuffer') diff --git a/files/pt-br/web/javascript/reference/global_objects/arraybuffer/index.html b/files/pt-br/web/javascript/reference/global_objects/arraybuffer/index.html new file mode 100644 index 0000000000..443a570305 --- /dev/null +++ b/files/pt-br/web/javascript/reference/global_objects/arraybuffer/index.html @@ -0,0 +1,148 @@ +--- +title: ArrayBuffer +slug: Web/JavaScript/Reference/Global_Objects/ArrayBuffer +tags: + - ArrayBuffer + - Constructor + - JavaScript + - TypedArrays +translation_of: Web/JavaScript/Reference/Global_Objects/ArrayBuffer +--- +

{{JSRef}}

+ +

O objeto ArrayBuffer é um tipo de dado usado para representar um genérico, buffer de dados binários de tamanho fixo. Você não pode manipular diretamente os conteúdos de um ArrayBuffer;  em vez disso, você cria um objeto ArrayBufferView que representa o buffer em um formato específico, e usa para ler e escrever os conteúdos do buffer.

+ +

{{EmbedInteractiveExample("pages/js/arraybuffer-constructor.html")}}

+ + + +

Syntax

+ +
new ArrayBuffer(length)
+
+ +

Parameters

+ +
+
length
+
The size, in bytes, of the array buffer to create.
+
+ +

Return value

+ +

A new ArrayBuffer object of the specified size. Its contents are initialized to 0.

+ +

Exceptions

+ +

A {{jsxref("RangeError")}} is thrown if the length is larger than {{jsxref("Number.MAX_SAFE_INTEGER")}} (>= 2 ** 53) or negative.

+ +

Description

+ +

The ArrayBuffer constructor creates a new ArrayBuffer of the given length in bytes.

+ +

Getting an array buffer from existing data

+ + + +

Properties

+ +
+
ArrayBuffer.length
+
The ArrayBuffer constructor's length property whose value is 1.
+
{{jsxref("ArrayBuffer.@@species", "get ArrayBuffer[@@species]")}}
+
The constructor function that is used to create derived objects.
+
{{jsxref("ArrayBuffer.prototype")}}
+
Allows the addition of properties to all ArrayBuffer objects.
+
+ +

Methods

+ +
+
{{jsxref("ArrayBuffer.isView", "ArrayBuffer.isView(arg)")}}
+
Returns true if arg is one of the ArrayBuffer views, such as typed array objects or a {{jsxref("DataView")}}. Returns false otherwise.
+
{{jsxref("ArrayBuffer.transfer", "ArrayBuffer.transfer(oldBuffer [, newByteLength])")}} {{experimental_inline}}
+
+

Returns a new ArrayBuffer whose contents are taken from the oldBuffer's data and then is either truncated or zero-extended by newByteLength.

+
+
+ +

Instances

+ +

All ArrayBuffer instances inherit from {{jsxref("ArrayBuffer.prototype")}}.

+ +

Properties

+ +

{{page('en-US/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/prototype','Properties')}}

+ +

Methods

+ +

{{page('en-US/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/prototype','Methods')}}

+ +
+
{{jsxref("ArrayBuffer.slice()")}} {{non-standard_inline}}
+
Has the same functionality as {{jsxref("ArrayBuffer.prototype.slice()")}}.
+
+ +

Exemplo

+ +

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);
+ +

Especificações

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificaçãoStatusComentário
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Substituído pelo ECMAScript 6
{{SpecName('ES6', '#sec-arraybuffer-constructor', 'ArrayBuffer')}}{{Spec2('ES6')}}Definição inicial no ECMA standard. Specified that new is required.
{{SpecName('ESDraft', '#sec-arraybuffer-constructor', 'ArrayBuffer')}}{{Spec2('ESDraft')}} 
+ +

Compatibilidade entre Navegadores

+ + + +

{{Compat("javascript.builtins.ArrayBuffer")}}

+ +

Compatibility notes

+ +

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);
+// TypedError: calling a builtin ArrayBuffer constructor
+// without new is forbidden
+ +
var dv = new ArrayBuffer(10);
+ +

Veja também

+ + -- cgit v1.2.3-54-g00ecf