1.关于使用let
与const
规则:
- 使用
let
声明的变量可以重新赋值,但是不能在同一作用域内重新声明 - 使用
const
声明的变量必须赋值初始化,但是不能在同一作用域类重新声明也无法重新赋值.
2.模板字面量本质上是包含嵌入式表达式的字符串字面量.
模板字面量用倒引号 ( `` )
(而不是单引号 ( '' )
或双引号( "" )
)表示,可以包含用 ${expression}
表示的占位符
3.解构
在ES6中,可以使用解构从数组和对象提取值并赋值给独特的变量
const gemstone = {
type: 'quartz',
color: 'rose',
karat: 21.29
};
const {type, color, karat} = gemstone;
console.log(type, color, karat);
4.对象字面量简写法
let type = 'quartz';
let color = 'rose';
let carat = 21.29;
const gemstone = {
type: type,
color: color,
carat: carat
};
console.log(gemstone);
5.for...of循环
for...of
循环用于循环访问任何可迭代的数据类型
6.展开运算符
const books = ["Don Quixote", "The Hobbit", "Alice in Wonderland", "Tale of Two Cities"];
console.log(...books);
7.ES6箭头函数
const upperizedNames = ['Farrin', 'Kagure', 'Asser'].map(
name => name.toUpperCase()
);
8.Javascript类
class Plane {
constructor(numEngines) {
this.numEngines = numEngines;
this.enginesActive = false;
}
static badWeather(planes) {
for (plane of planes) {
plane.enginesActive = false;
}
}
startEngines() {
console.log('starting engines…');
this.enginesActive = true;
}
}
9.super 和 extends
class Tree {
constructor(size = '10', leaves = {spring: 'green', summer: 'green', fall: 'orange', winter: null}) {
this.size = size;
this.leaves = leaves;
this.leafColor = null;
}
changeSeason(season) {
this.leafColor = this.leaves[season];
if (season === 'spring') {
this.size += 1;
}
}
}
class Maple extends Tree {
constructor(syrupQty = 15, size, leaves) {
super(size, leaves); //super用作函数
this.syrupQty = syrupQty;
}
changeSeason(season) {
super.changeSeason(season);//super用作对象
if (season === 'spring') {
this.syrupQty += 1;
}
}
gatherSyrup() {
this.syrupQty -= 3;
}
}