ES6(ES2015)
1、Let 和 Const
2、类
class Person {
constructor(name, age) {
this.name = name
this.age = age
}
information() {
return 'My name is ' + this.name + ', I am ' + this.age
}
}
3、箭头函数
const list = [1, 2, 3, 4, 5, 6, 7]
const newList = list.map(item => item * item)
4、函数参数默认值
const config = (data = 'data is empty') => {}
5、模板字符串
const name = 'kris'
const age = 24
const info = `My name is ${name}, I am ${age}`
6、解构赋值
let a = 10
let b = 20
[a, b] = [b, a]
7、模块化
8、扩展操作符
9、对象属性简写
普通写法
var cat = 'Miaow'
var someObject = {
cat: cat
}
es6写法
let cat = 'Miaow'
let someObject = {
cat
}
console.log(someObject)
//{
// cat: "Miaow"
//}
10、Promise (*链式调用)
11、for…of
12、Symbol
13、迭代器(Iterator)/ 生成器(Generator)
14、Set/WeakSet
15、Map/WeakMap
16、Proxy/Reflect
18、Regex(正则表达式)对象的扩展
新增符号
- i 修饰符
- y修饰符
19、Math对象的扩展
二进制表示法 : 0b或0B开头表示二进制(0bXX或0BXX)
二进制表示法 : 0b或0B开头表示二进制(0bXX或0BXX)
八进制表示法 : 0o或0O开头表示二进制(0oXX或0OXX)
Number.EPSILON : 数值最小精度
Number.MIN_SAFE_INTEGER : 最小安全数值(-2^53)
Number.MAX_SAFE_INTEGER : 最大安全数值(2^53)
Number.parseInt() : 返回转换值的整数部分
Number.parseFloat() : 返回转换值的浮点数部分
Number.isFinite() : 是否为有限数值
Number.isNaN() : 是否为NaN
Number.isInteger() : 是否为整数
Number.isSafeInteger() : 是否在数值安全范围内
Math.trunc() : 返回数值整数部分
Math.sign() : 返回数值类型(正数1、负数-1、零0)
Math.cbrt() : 返回数值立方根
Math.clz32() : 返回数值的32位无符号整数形式
Math.imul() : 返回两个数值相乘
Math.fround() : 返回数值的32位单精度浮点数形式
Math.hypot() : 返回所有数值平方和的平方根
Math.expm1() : 返回e^n - 1
Math.log1p() : 返回1 + n的自然对数(Math.log(1 + n))
Math.log10() : 返回以10为底的n的对数
Math.log2() : 返回以2为底的n的对数
Math.sinh() : 返回n的双曲正弦
Math.cosh() : 返回n的双曲余弦
Math.tanh() : 返回n的双曲正切
Math.asinh() : 返回n的反双曲正弦
Math.acosh() : 返回n的反双曲余弦
Math.atanh() : 返回n的反双曲正切
20、Array对象的扩展
Array.from:转换数据结构并返回新数组
console.log(Array.from('foo')) // ["f", "o", "o"]
console.log(Array.from([1, 2, 3], x => x + x)) // [2, 4, 6]
Array.of():转换一组值为数组,返回新数组
Array.of(7) // [7]
Array.of(1, 2, 3) // [1, 2, 3]
Array(7) // [empty, empty, empty, empty, empty, empty]
Array(1, 2, 3) // [1, 2, 3]
Array.copyWithin():把指定位置的成员复制到其他位置,返回原数组
const array1 = ['a', 'b', 'c', 'd', 'e']
console.log(array1.copyWithin(0, 3, 4)) // ["d", "b", "c", "d", "e"]
console.log(array1.copyWithin(1, 3)) // ["d", "d", "e", "d", "e"]
Array.find():返回第一个符合条件的成员
const array1 = [5, 12, 8, 130, 44]
const found = array1.find(element => element > 10)
console.log(found) // 12
Array.findIndex():返回第一个符合条件的成员索引值
const array1 = [5, 12, 8, 130, 44]
const isLargeNumber = (element) => element > 13
console.log(array1.findIndex(isLargeNumber)) // 3
Array.fill():根据指定值填充整个数组,返回原数组
const array1 = [1, 2, 3, 4]
console.log(array1.fill(0, 2, 4)) // [1, 2, 0, 0]
console.log(array1.fill(5, 1)) // [1, 5, 5, 5]
console.log(array1.fill(6)) // [6, 6, 6, 6]
Array.keys():返回以索引值为遍历器的对象
const array1 = ['a', 'b', 'c']
const iterator = array1.keys()
for (const key of iterator) {
console.log(key)
}
// 0
// 1
// 2
Array.values():返回以属性值为遍历器的对象
const array1 = ['a', 'b', 'c']
const iterator = array1.values()
for (const key of iterator) {
console.log(key)
}
// a
// b
// c
Array.entries():返回以索引值和属性值为遍历器的对象
const array1 = ['a', 'b', 'c']
const iterator = array1.entries()
console.log(iterator.next().value) // [0, "a"]
console.log(iterator.next().value) // [1, "b"]
数组空位:ES6明确将数组空位转为undefined或者empty
Array.from(['a',,'b']) // [ "a", undefined, "b" ]
[...['a',,'b']] // [ "a", undefined, "b" ]
Array(3) // [empty × 3]
[,'a'] // [empty, "a"]
ES7(ES2016)
Array.includes()
const array1 = [1, 2, 3]
console.log(array1.includes(2)) // true
幂运算符** 具有与Math.pow()一样的功能,代码如下
console.log(2**10) // 1024
console.log(Math.pow(2, 10)) // 1024
模板字符串(Template string)
在这里插入代码片