ES6新特性
const 与 let 变量
模板字面量(``)
解构
const point = [10, 25, -34]; const [x, y, z] = point; console.log(x, y, z);
对象字面量简写法
let type = 'quartz'; let color = 'rose'; let carat = 21.29; const gemstone = {type,color,carat}; console.log(gemstone);
for...of循环&Iterator
let arr = ['a', 'b', 'c']; let iter = arr[Symbol.iterator](); iter.next() // { value: 'a', done: false } iter.next() // { value: 'b', done: false } iter.next() // { value: 'c', done: false } iter.next() // { value: undefined, done: true }
展开运算符
{name:'lilei',...student}//修改值
[...fruits,...books]//合并数组
箭头函数
默认参数函数(default值)
Class类组件
本质是函数
super 和 extends
Modules
Set与Map
Generator函数
function* helloWorldGenerator() { yield 'hello'; yield 'world'; return 'ending'; } var hw = helloWorldGenerator();
async&await
var asyncReadFile = async function (){ var f1 = await readFile('/etc/fstab'); var f2 = await readFile('/etc/shells'); console.log(f1.toString()); console.log(f2.toString()); };
类的修饰
@testable
fetch(代替了XMLHttpRequest)
fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); .then((response) => response.json()) .catch((error) => console.log(error))
call,apply,bind
call参数,apply数组,bind修改this指针指向