aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/javascript/reference/global_objects/arraybuffer
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
commit074785cea106179cb3305637055ab0a009ca74f2 (patch)
treee6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/pt-br/web/javascript/reference/global_objects/arraybuffer
parentda78a9e329e272dedb2400b79a3bdeebff387d47 (diff)
downloadtranslated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz
translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2
translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip
initial commit
Diffstat (limited to 'files/pt-br/web/javascript/reference/global_objects/arraybuffer')
-rw-r--r--files/pt-br/web/javascript/reference/global_objects/arraybuffer/index.html148
1 files changed, 148 insertions, 0 deletions
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
+---
+<p>{{JSRef}}</p>
+
+<p>O objeto <strong><code>ArrayBuffer</code></strong> é um tipo de dado usado para representar um genérico, <span class="short_text" id="result_box" lang="pt"><span class="hps">buffer de</span> <span class="hps">dados binários</span> <span class="hps">de tamanho</span> <span class="hps">fixo</span></span>. Você não pode manipular diretamente os conteúdos de um <code>ArrayBuffer</code>;  em vez disso, você cria um objeto <a href="/en/JavaScript_typed_arrays/ArrayBufferView" title="en/JavaScript typed arrays/ArrayBufferView"><code>ArrayBufferView</code></a> que representa o buffer em um formato específico, e usa para ler e escrever os conteúdos do buffer.</p>
+
+<p>{{EmbedInteractiveExample("pages/js/arraybuffer-constructor.html")}}</p>
+
+<div class="hidden">
+<p>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 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
+</div>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre>new ArrayBuffer(length)
+</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt><code>length</code></dt>
+ <dd>The size, in bytes, of the array buffer to create.</dd>
+</dl>
+
+<h3 id="Return_value">Return value</h3>
+
+<p>A new <code>ArrayBuffer</code> object of the specified size. Its contents are initialized to 0.</p>
+
+<h3 id="Exceptions">Exceptions</h3>
+
+<p>A {{jsxref("RangeError")}} is thrown if the <code>length</code> is larger than {{jsxref("Number.MAX_SAFE_INTEGER")}} (&gt;= 2 ** 53) or negative.</p>
+
+<h2 id="Description">Description</h2>
+
+<p>The <code>ArrayBuffer</code> constructor creates a new <code>ArrayBuffer</code> of the given length in bytes.</p>
+
+<h3 id="Getting_an_array_buffer_from_existing_data">Getting an array buffer from existing data</h3>
+
+<ul>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Appendix.3A_Decode_a_Base64_string_to_Uint8Array_or_ArrayBuffer">From a Base64 string</a></li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader#readAsArrayBuffer()">From a local file</a></li>
+</ul>
+
+<h2 id="Properties">Properties</h2>
+
+<dl>
+ <dt><code>ArrayBuffer.length</code></dt>
+ <dd>The <code>ArrayBuffer</code> constructor's length property whose value is 1.</dd>
+ <dt>{{jsxref("ArrayBuffer.@@species", "get ArrayBuffer[@@species]")}}</dt>
+ <dd>The constructor function that is used to create derived objects.</dd>
+ <dt>{{jsxref("ArrayBuffer.prototype")}}</dt>
+ <dd>Allows the addition of properties to all <code>ArrayBuffer</code> objects.</dd>
+</dl>
+
+<h2 id="Methods">Methods</h2>
+
+<dl>
+ <dt>{{jsxref("ArrayBuffer.isView", "ArrayBuffer.isView(arg)")}}</dt>
+ <dd>Returns <code>true</code> if <code>arg</code> is one of the ArrayBuffer views, such as <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray">typed array objects</a> or a {{jsxref("DataView")}}. Returns <code>false</code> otherwise.</dd>
+ <dt>{{jsxref("ArrayBuffer.transfer", "ArrayBuffer.transfer(oldBuffer [, newByteLength])")}} {{experimental_inline}}</dt>
+ <dd>
+ <p>Returns a new <code>ArrayBuffer</code> whose contents are taken from the <code>oldBuffer</code>'s data and then is either truncated or zero-extended by <code>newByteLength</code>.</p>
+ </dd>
+</dl>
+
+<h2 id="Instances">Instances</h2>
+
+<p>All <code>ArrayBuffer</code> instances inherit from {{jsxref("ArrayBuffer.prototype")}}.</p>
+
+<h3 id="Properties_2">Properties</h3>
+
+<p>{{page('en-US/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/prototype','Properties')}}</p>
+
+<h3 id="Methods_2">Methods</h3>
+
+<p>{{page('en-US/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/prototype','Methods')}}</p>
+
+<dl>
+ <dt>{{jsxref("ArrayBuffer.slice()")}} {{non-standard_inline}}</dt>
+ <dd>Has the same functionality as {{jsxref("ArrayBuffer.prototype.slice()")}}.</dd>
+</dl>
+
+<h2 id="Exemplo">Exemplo</h2>
+
+<p>In this example, we create a 8-byte buffer with a {{jsxref("Global_Objects/Int32Array", "Int32Array")}} view referring to the buffer:</p>
+
+<pre><code>var buffer = new ArrayBuffer(8);
+var view = new Int32Array(buffer);</code></pre>
+
+<h2 id="Especificações">Especificações</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificação</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comentário</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Typed Array')}}</td>
+ <td>{{Spec2('Typed Array')}}</td>
+ <td>Substituído pelo ECMAScript 6</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-arraybuffer-constructor', 'ArrayBuffer')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td>Definição inicial no ECMA standard. Specified that <code>new</code> is required.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-arraybuffer-constructor', 'ArrayBuffer')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_entre_Navegadores">Compatibilidade entre Navegadores</h2>
+
+<div class="hidden">
+<p>The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+</div>
+
+<p>{{Compat("javascript.builtins.ArrayBuffer")}}</p>
+
+<h2 id="Compatibility_notes">Compatibility notes</h2>
+
+<p>Starting with ECMAScript 2015, <code>ArrayBuffer</code> constructors require to be constructed with a {{jsxref("Operators/new", "new")}} operator. Calling an <code>ArrayBuffer</code> constructor as a function without <code>new</code>, will throw a {{jsxref("TypeError")}} from now on.</p>
+
+<pre class="brush: js example-bad">var dv = ArrayBuffer(10);
+// TypedError: calling a builtin ArrayBuffer constructor
+// without new is forbidden</pre>
+
+<pre class="brush: js example-good">var dv = new ArrayBuffer(10);</pre>
+
+<h2 id="Veja_também">Veja também</h2>
+
+<ul>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays">JavaScript typed arrays</a></li>
+ <li>{{jsxref("SharedArrayBuffer")}}</li>
+</ul>