Skip to content

Instantly share code, notes, and snippets.

View victorvhpg's full-sized avatar
🎯
Focusing

Victor Hugo victorvhpg

🎯
Focusing
View GitHub Profile
var obj = {
getNome(){
return this.nome;
}
};
//seria o equivalente:
var obj = {
getNome: function(){
return this.nome;
}
@victorvhpg
victorvhpg / obj.js
Created November 7, 2016 22:33
obj.js
var a = 1;
var b = 2;
var obj = {a, b};
console.log(obj); // {a: 1, b: 2}
//seria o mesmo que
var a = 1;
var b = 2;
var obj = {
a: a,
b: b
@victorvhpg
victorvhpg / arrow3.js
Created November 7, 2016 22:26
arrow
var list = [1,2,3];
list.map(item => item + "#");
list.map( (item, indice) => item + "#" + indice);
//equivalente:
list.map(function(item){
return item + "#";
});
@victorvhpg
victorvhpg / arrow2.js
Created November 7, 2016 22:22
arrow
let fn = (p1) => ({ id: p1, nome: "teste"});
fn(1);//{id:1, nome: "teste"}
@victorvhpg
victorvhpg / arrow.js
Created November 7, 2016 22:20
arrow.js
//Caso não tenha parâmetro pode-se fazer o seguinte
let fn = () => 3;
fn(); //3
//Caso tenha apenas um parametro não é necessário colocar parenteses:
let fn = p1 => p1;
fn(3); //3
@victorvhpg
victorvhpg / spread.js
Created November 7, 2016 07:21
spread.js
let arrayValores = [5, 50, 25, 100]
console.log(Math.max(...arrayValores)); // 100
//equivalente:
Math.max(5, 50, 25, 100);
//ou
Math.max.apply(Math, arrayValores);
@victorvhpg
victorvhpg / rest.js
Created November 7, 2016 00:19
rest
function teste(a, ...b){
console.log(a);
console.log(b);
}
teste("oi", "la" , "se", "ls");
//oi, ["la", "se", "ls"]
@victorvhpg
victorvhpg / parametro.js
Last active November 7, 2016 00:02
parametro valor padrao
function teste(a, b=1, c="oi"){
console.log(b);
console.log(c);
}
teste(9); // 1,2
teste("k" ,false, "B"); //false,B
teste("a", undefined, 9); // 1,9 //undefined é considerado que o parametro não foi informado
//podemos usar expressoes como valores padroes
@victorvhpg
victorvhpg / tag.js
Last active November 6, 2016 23:15
tag.js
function tagTeste(arrayString, ...arraySubstituicoes) {
console.log(arrayString);// ["oi "," tudo bem?"] //também possui a propriedade .raw que é a string crua
console.log(arraySubstituicoes);//["teste"]
return "olá";
}
var a = "teste";
var b = tagTeste`oi ${a} tudo bem?`;
console.log(b); //olá
@victorvhpg
victorvhpg / substituicao.js
Created November 6, 2016 21:20
substituicao.js
var variavel = "oi teste"
var teste = `
texto ${variavel}
texto
texto
`;
var teste2 = `texto ${teste} fim`;
console.log(teste2);