This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Retangulo{ | |
constructor(largura, altura){ | |
this.largura = largura; | |
this.altura = altura; | |
} | |
getArea(){ | |
return this.largura * this.altura; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Retangulo(largura, altura) { | |
this.largura = largura; | |
this.altura = altura; | |
} | |
Retangulo.prototype.getArea = function() { | |
return this.largura * this.altura; | |
}; | |
function Quadrado(lado) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Pessoa = (function() { | |
"use strict"; | |
const Pessoa = function(name) { | |
//valida se foi chamada com new | |
if (typeof new.target === "undefined") { | |
throw new Error("Somente deve ser chamada com new."); | |
} | |
this.name = name; | |
} | |
Object.defineProperty(Pessoa.prototype, "getNome", { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Pessoa(nome){ | |
this.nome = nome; | |
} | |
Pessoa.prototype.getNome = function(){ | |
return this.nome; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Declaração | |
class Pessoa { | |
constructor(nome) { | |
this.nome = nome; | |
} | |
getNome() { | |
return this.nome; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//com parametro nomeado opcional | |
function teste(a, { b, c = 5}){ | |
console.log(a); | |
console.log(b); | |
console.log(c); | |
}; | |
teste(1, { b: "oi" }); //1, "oi", 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let list = ["aaa", "bbb" , "ccc"]; | |
let [a, ...b] = list; | |
console.log(a); //aaa | |
console.log(b); //["bbb", "ccc"] | |
//podemos 'clonar' um array utilizando Rest Itens | |
let [...listClone] = list; | |
console.log(listClone);//["aaa", "bbb" , "ccc"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let list = ["aaa", "bbb" , "ccc"]; | |
let [a,b,c] = list; | |
console.log(a); //aaa | |
console.log(b); //bbb | |
console.log(c); //ccc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//considerando o seguinte objeto | |
let obj = { | |
a: "olá", | |
b: "oi", | |
c: "teste", | |
d: { | |
filho: { | |
idade: 1 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = "getNome"; | |
var obj = { | |
[a + "DoFulano"]: function(){ | |
return "teste"; | |
} | |
}; | |
obj.getNomeDoFulano();//teste |