Skip to content

Instantly share code, notes, and snippets.

View victorvhpg's full-sized avatar
🎯
Focusing

Victor Hugo victorvhpg

🎯
Focusing
View GitHub Profile
class Retangulo{
constructor(largura, altura){
this.largura = largura;
this.altura = altura;
}
getArea(){
return this.largura * this.altura;
}
}
function Retangulo(largura, altura) {
this.largura = largura;
this.altura = altura;
}
Retangulo.prototype.getArea = function() {
return this.largura * this.altura;
};
function Quadrado(lado) {
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", {
function Pessoa(nome){
this.nome = nome;
}
Pessoa.prototype.getNome = function(){
return this.nome;
};
//Declaração
class Pessoa {
constructor(nome) {
this.nome = nome;
}
getNome() {
return this.nome;
}
};
//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
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"]
let list = ["aaa", "bbb" , "ccc"];
let [a,b,c] = list;
console.log(a); //aaa
console.log(b); //bbb
console.log(c); //ccc
//considerando o seguinte objeto
let obj = {
a: "olá",
b: "oi",
c: "teste",
d: {
filho: {
idade: 1
}
}
var a = "getNome";
var obj = {
[a + "DoFulano"]: function(){
return "teste";
}
};
obj.getNomeDoFulano();//teste