diff options
Diffstat (limited to 'files/pt-br/web/javascript/reference/global_objects/array/unobserve/index.html')
-rw-r--r-- | files/pt-br/web/javascript/reference/global_objects/array/unobserve/index.html | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/files/pt-br/web/javascript/reference/global_objects/array/unobserve/index.html b/files/pt-br/web/javascript/reference/global_objects/array/unobserve/index.html new file mode 100644 index 0000000000..a509f16afb --- /dev/null +++ b/files/pt-br/web/javascript/reference/global_objects/array/unobserve/index.html @@ -0,0 +1,129 @@ +--- +title: Array.unobserve() +slug: Web/JavaScript/Reference/Global_Objects/Array/unobserve +translation_of: Archive/Web/JavaScript/Array.unobserve +--- +<div>{{JSRef}}</div> + +<div>O método Array<strong>.unobserve()</strong> é usado para remover observers adicionados pelo {{jsxref("Array.observe()")}}.</div> + +<div> </div> + +<h2 id="Sintaxe">Sintaxe</h2> + +<pre class="syntaxbox"><code>Array.unobserve(<var>arr</var>, <var>callback</var>)</code></pre> + +<h3 id="Parâmetros">Parâmetros</h3> + +<dl> + <dt><code>arr</code></dt> + <dd>O array para remover os observers.</dd> + <dt><code>callback</code></dt> + <dd><code>A referência para o observer para parar de ser chamada a toda vez em que algo é modificado no array </code><strong>arr</strong>.</dd> +</dl> + +<h2 id="Descrição">Descrição</h2> + +<p><code>Array.unobserve()</code> deve ser chamado após o {{jsxref("Array.observe()")}} a fim de remover um observers de um array.</p> + +<p>O callback deve ser uma referencia à uma função e não a uma função anônima, porquê esta referencia será usada para remover o observer anterior. É inútil chamar o <strong>Array.unobserve() </strong>com uma função anônima como callback, não removerá nenhum observer.</p> + +<h2 id="Exemplos">Exemplos</h2> + +<h3 id="Desobservando_um_array">Desobservando um array</h3> + +<pre class="brush: js">var arr = [1, 2, 3]; + +var observer = function(changes) { + console.log(changes); +} + +Array.observe(arr, observer); + +arr.push(4); +// [{type: "splice", object: <arr>, index: 3, removed:[], addedCount: 1}] + +Array.unobserve(arr, observer); + +arr.pop(); +// O callback não foi chamado</pre> + +<h3 id="Usando_uma_função_anônima">Usando uma função anônima</h3> + +<pre class="brush: js">var persons = ['Khalid', 'Ahmed', 'Mohammed']; + +Array.observe(persons, function (changes) { + console.log(changes); +}); + +persons.shift(); +// [{type: "splice", object: <arr>, index: 0, removed: [ "Khalid" ], addedCount: 0 }] + +Array.unobserve(persons, function (changes) { + console.log(changes); +}); + +persons.push('Abdullah'); +// [{type: "splice", object: <arr>, index: 2, removed: [], addedCount: 1 }] +// O callback sempre será chamado +</pre> + +<h2 id="Compatibilidade_com_os_navegadores">Compatibilidade com os navegadores</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Suporte básico</td> + <td>{{CompatChrome("36")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatOpera("23")}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Suporte básico</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome("36")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatOpera("23")}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Ver_também">Ver também</h2> + +<ul> + <li>{{jsxref("Array.observe()")}} {{experimental_inline}}</li> + <li>{{jsxref("Object.observe()")}} {{experimental_inline}}</li> + <li>{{jsxref("Object.unobserve()")}} {{experimental_inline}}</li> +</ul> |