aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/javascript/reference/classes/extends
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/classes/extends
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/classes/extends')
-rw-r--r--files/pt-br/web/javascript/reference/classes/extends/index.html106
1 files changed, 106 insertions, 0 deletions
diff --git a/files/pt-br/web/javascript/reference/classes/extends/index.html b/files/pt-br/web/javascript/reference/classes/extends/index.html
new file mode 100644
index 0000000000..534a1c2e33
--- /dev/null
+++ b/files/pt-br/web/javascript/reference/classes/extends/index.html
@@ -0,0 +1,106 @@
+---
+title: extends
+slug: Web/JavaScript/Reference/Classes/extends
+tags:
+ - Classes
+ - ECMAScript6
+ - Experimental
+ - Herança
+ - JavaScript
+ - extends
+translation_of: Web/JavaScript/Reference/Classes/extends
+---
+<div>{{jsSidebar("Classes")}}</div>
+
+<p>A palavra chave <strong><code>extends</code></strong> é usada em uma <a href="/en-US/docs/Web/JavaScript/Reference/Statements/class">class declarations</a> ou <a href="/en-US/docs/Web/JavaScript/Reference/Operators/class">class expressions</a> para criar uma classe filha de outra classe.</p>
+
+<h2 id="Sintaxe">Sintaxe</h2>
+
+<pre class="syntaxbox">class ChildClass extends ParentClass { ... }</pre>
+
+<h2 id="Descrição">Descrição</h2>
+
+<p>A palavra chave extends pode ser usada para tanto classes filhas quanto objetos filhos pré-construidos.</p>
+
+<p>O <code>.prototype</code> da extensão deve ser um {{jsxref("Object")}} ou {{jsxref("null")}}.</p>
+
+<h2 id="Exemplos">Exemplos</h2>
+
+<h3 id="Usando_extends">Usando <code>extends</code></h3>
+
+<p>O primeiro exemplo cria uma classe chamada <code>Square</code> a partir de uma classe chamada <code>Polygon</code>. Este exemplo foi extraido deste <a href="https://googlechrome.github.io/samples/classes-es6/index.html">live demo</a> <a href="https://github.com/GoogleChrome/samples/blob/gh-pages/classes-es6/index.html">(source)</a>.</p>
+
+<pre class="brush: js">class Square extends Polygon {
+ constructor(length) {
+ // Here, it calls the parent class' constructor with lengths
+ // provided for the Polygon's width and height
+ super(length, length);
+ // Note: In derived classes, super() must be called before you
+ // can use 'this'. Leaving this out will cause a reference error.
+ this.name = 'Square';
+ }
+
+ get area() {
+ return this.height * this.width;
+ }
+
+ set area(value) {
+ this.area = value;
+ }
+}</pre>
+
+<h3 id="Usando_extends_com_objetos_pré-construidos">Usando <code>extends</code> com objetos pré-construidos</h3>
+
+<p>Este exemplo extende o objeto pré-construido {{jsxref("Date")}}. Este exemplo foi extraido deste <a href="https://googlechrome.github.io/samples/classes-es6/index.html">live demo</a> <a href="https://github.com/GoogleChrome/samples/blob/gh-pages/classes-es6/index.html">(source)</a>.</p>
+
+<pre class="brush: js">class myDate extends Date {
+ constructor() {
+ super();
+ }
+
+ getFormattedDate() {
+ var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
+ return this.getDate() + "-" + months[this.getMonth()] + "-" + this.getFullYear();
+ }
+}</pre>
+
+<h3 id="Estendendo_null">Estendendo <code>null</code></h3>
+
+<p>Estender de {{jsxref("null")}} funciona como em uma classe normal, exceto que o objeto prototype não herda de {{jsxref("Object.prototype")}}.</p>
+
+<pre class="brush: js"><code>class nullExtends extends null {
+ constructor() {}
+}
+
+Object.getPrototypeOf(nullExtends); // Function.prototype
+Object.getPrototypeOf(nullExtends.prototype) // null</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('ES6', '#sec-class-definitions', 'extends')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td>Definição inicial.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_com_os_navegadores">Compatibilidade com os navegadores</h2>
+
+
+
+<p>{{Compat("javascript.classes.extends")}}</p>
+
+<h2 id="Ver_também">Ver também</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/JavaScript/Reference/Classes">Classes</a></li>
+ <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/super">super</a></li>
+</ul>