- 不一样的变量声明:const和let
let表示声明变量,而const表示声明常量
2. 模板字符串
以前:通过“\”和“+”来构建模板
现在:基本的字符串格式化。将表达式嵌入字符串中进行拼接。用${}来界定; ES6反引号(``)直接搞定
3. 箭头函数
特点:
不需要 function 关键字来创建函数
省略 return 关键字
继承当前上下文的 this 关键字
问题:箭头函数的this和js的this有什么区别?
答: 普通函数只要记住this 永远指向调用它的对象,new的时候,指向new出来的对象。
箭头函数没有自己的 this,当在内部使用了 this时,它会指向最近一层作用域内的 this。
4. 函数的参数默认值
function printText(param={}) {
console.log(param);
}
5. Spread / Rest 操作符
6. 二进制和八进制字面量
7. 对象和数组解构
const { name, age, sex } = student;
8. 对象超类(super(props))
9. for…of 和 for…in
for…of 用于遍历一个迭代器,如数组
let letters = [‘a’, ‘b’, ‘c’];
letters.size = 3;
for (let letter of letters) {
console.log(letter);
}
for…in 用来遍历对象中的属性
let stus = [“Sam”, “22”, “男”];
for (let stu in stus) {
console.log(stus[stu]);
}
10.ES6中的类