Skip to content

Instantly share code, notes, and snippets.

View victorvhpg's full-sized avatar
🎯
Focusing

Victor Hugo victorvhpg

🎯
Focusing
View GitHub Profile
//modulo-teste.js
//exportando variaveis
export var cor = "amarelo";
export let nome = "Pikachu";
export const peso = 20;
// exportando function
export function soma(num1, num2) {
return num1 + num1;
class Retangulo{
constructor(largura, altura){
//...
}
static métodoEstatico(){
return "alguma coisa";
}
};
console.log(Retangulo.métodoEstatico());//"alguma coisa"
class Quadrado extends Retangulo {
// sem constructor
}
// é equivalente
class Quadrado extends Retangulo {
constructor(...parâmetros) {
super(...parâmetros);
}
}
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"]