Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:总结的不错, 继续加油
1. 值数量 < 变量数量, 默认值
;[uname, phone, gender ] = ['Mr.Y', '18095411***','男']
console.log(uname, phone, gender)
代码运行结果:Mr.Y 18095411*** 男
2. 值数量 > 变量数量, ...rest
;[uname, ...arr] = ['M','18095','男']
console.log(uname,...arr)
代码运行结果:M 18095 男
let { num, goods } = { num: 2, goods: 3000 }
console.log(num, goods)
;({ num, goods } = { num: 1, goods: 6000 })
console.log(num, goods)
运行代码结果:
2 3000
1 6000
let course = {
jslesson: {
name: 'JS',
score: 80,
},
getScore() {
return {
name: this.jslesson.name,
course: this.jslesson.score,
}
},
setScore(score) {
if (score >= 0 && score <= 100) {
this.jslesson.score = score
} else {
console.log('成绩必须在1-100分之间')
}
},
}
console.log(course.jslesson.score)
console.log(course.getScore())
course.setScore(69)
console.log(course.getScore())
运行结果:
80
{ name: 'JS', course: 80 }
{ name: 'JS', course: 69 }