ES6+

参数默认值

function decimal(num, fix = 2) {
    return +num.toFixed(fix);
}

模板字符串

 

解构赋值

// 函数入参默认值解构
function example({x, y, z = 0}) { return x + y + z; } console.log(example({x: 1, y: 2})); // => 3 console.log(example({x: 1, y: 2, z: 3})); // => 6

Let & Const

无变量提升

有块级作用域

禁止重复声明  

其中const区别:(禁止重复赋值)(必须附初始值)

let aa; // 不报错

const bb: // 报错

新增库函数

Number.EPSILON
Number.isInteger(Infinity); // => false
Number.isNaN('NaN');        // => false

Number.parseInt('33thh3.33') // 33
Number.parseFloat('33thh3.33') // 33

'abcde'.includes('cd'); // => true
'abc'.repeat(3);        // => 'abcabcabc'
'abc'.startsWith('a');  // => true
'abc'.endsWith('c');    // => true

array.fill(value, start, end)
[0, 0, 0, 0].fill(7, 1, 3); // => [0, 7, 7, 0]

[1, 2, 3].findIndex(function(x) {
    return x === 2;
}); // => 1
['a', 'b', 'c'].entries(); // => Iterator [0: 'a'], [1: 'b'], [2: 'c']
['a', 'b', 'c'].keys();    // => Iterator 0, 1, 2
['a', 'b', 'c'].values();  // => Iterator 'a', 'b', 'c'
// Before
new Array();        // => []
new Array(4);       // => [,,,]
new Array(4, 5, 6); // => [4, 5, 6]
// After
Array.of();         // => []
Array.of(4);        // => [4]
Array.of(4, 5, 6);  // => [4, 5, 6]
Object.assign(target, source); // => { a: 1, b: 2, c: 3} 浅拷贝
// 判断一个函数的正负
Math.sign(5); // => +1 Math.sign(0); // => 0 Math.sign(-5); // => -1 // 取数值的整数部分 Math.trunc(4.1); // => 4 Math.trunc(-4.1); // => -4
Math.floor(-4.1); // => -5

(上)https://zhuanlan.zhihu.com/p/26589735

 

箭头函数

类 & 继承

模块

import example from './example.js';
import default as example from './example.js';
// 上面2种是一样的

  (下)https://zhuanlan.zhihu.com/p/26590942

 

 

 

 

 

 

 

 

 

 

.

 

posted @ 2020-07-08 13:25  James2019  阅读(122)  评论(0编辑  收藏  举报