This file contains 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
//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; |
This file contains 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){ | |
//... | |
} | |
static métodoEstatico(){ | |
return "alguma coisa"; | |
} | |
}; | |
console.log(Retangulo.métodoEstatico());//"alguma coisa" |
This file contains 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 Quadrado extends Retangulo { | |
// sem constructor | |
} | |
// é equivalente | |
class Quadrado extends Retangulo { | |
constructor(...parâmetros) { | |
super(...parâmetros); | |
} | |
} |
This file contains 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 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 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 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 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 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 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"] |