1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| 1、类(class)
class Man { constructor(name) { this.name = '赵十三'; } console() { console.log(this.name); } } const man = new Man('赵十三'); man.console();
2、模块化(ES Module)
export const sub = (a, b) => a + b;
import { sub } from './A'; console.log(sub(1, 2));
3、箭头(Arrow)函数
const func = (a,b) => console.log(a + b); func(1,2)
4、函数参数默认值
function func(a = 11,){ console.log(a) }
5、模板字符串
const name = '赵十三' const str = `我的名字是${name}` console.log(str)
6、解构赋值(注意范例里边的重点注意事项)
var a, b, rest; [a, b] = [10, 20]; console.log(a); console.log(b);
[a, b, ...rest] = [10, 20, 30, 40, 50]; console.log(a); console.log(b); console.log(rest);
({ a, b } = { a: 10, b: 20 }); console.log(a); console.log(b);
({a, b, ...rest} = {a: 10, b: 20, c: 30, d: 40}); console.log(a); console.log(b); console.log(rest);
a = 1;b = 3; [a, b] = [b, a]; console.log(a); console.log(b);
7、延展操作符
let a = [...'hello world'];
8、对象属性简写
const name='小豪', const obj = { name };
9、Promise
Promise.resolve().then(() => { console.log(2); }); console.log(1);
10、let和const
let name = '小豪' const arr = [];
|