Wednesday, April 17, 2019
Tuesday, April 2, 2019
ES2018简介
中括号
const numbers = [1, 2, 3, 4, 5]
[first, second, ...others] = numbers
小括号
const numbers = [1, 2, 3, 4, 5]
const sum = (a, b, c, d, e) => a + b + c + d + e
const sumOfNumbers = sum(...numbers)
大括号
const { first, second, ...others } = { first: 1, second: 2, third: 3, fourth: 4, fifth: 5 }
first // 1
second // 2
others // { third: 3, fourth: 4, fifth: 5 }
const items = { first, second, ...others }
items //{ first: 1, second: 2, third: 3, fourth: 4, fifth: 5 }
some:
return the first one-> true/false without going through all elements
[2, 5, 8, 1, 4].some(isBiggerThan10);
map:
let r = res.map(item => {
return {
title: item.name,
sex: item.sex === 1? '男':item.sex === 0?'女':'保密',
age: item.age,
avatar: item.img
}
})
filter:
var marvelHeroes = heroes.filter(function(hero) {
return hero.franchise == “Marvel”;
});
ES2018
const numbers = [1, 2, 3, 4, 5]
[first, second, ...others] = numbers
小括号
const numbers = [1, 2, 3, 4, 5]
const sum = (a, b, c, d, e) => a + b + c + d + e
const sumOfNumbers = sum(...numbers)
大括号
const { first, second, ...others } = { first: 1, second: 2, third: 3, fourth: 4, fifth: 5 }
first // 1
second // 2
others // { third: 3, fourth: 4, fifth: 5 }
const items = { first, second, ...others }
items //{ first: 1, second: 2, third: 3, fourth: 4, fifth: 5 }
some:
return the first one-> true/false without going through all elements
[2, 5, 8, 1, 4].some(isBiggerThan10);
map:
let r = res.map(item => {
return {
title: item.name,
sex: item.sex === 1? '男':item.sex === 0?'女':'保密',
age: item.age,
avatar: item.img
}
})
filter:
var marvelHeroes = heroes.filter(function(hero) {
return hero.franchise == “Marvel”;
});
ES2018
Subscribe to:
Posts (Atom)