Blogger Information
Blog 3
fans 0
comment 0
visits 915
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组的解构赋值和访问属性
皮卡丘
Original
260 people have browsed it

// todo 访问器属性
// 普通属性和访问属性
// 访问属性
// 访问属性修改属性可以获取修改后属性的值

// 普通函数
// 普通属性修改属性值必须调用函数才能获取属性的值并返回获取到的值,

let course = {
lesson: {
name: ‘ES6’,
score: 60,
},
// 读取接口
getScore() {
return {
name: this.lesson.name,
course: this.lesson.score,
}
},
// 设置接口
setScore(score) {
if (score >= 0 && score <= 100) {
this.lesson.score = score
} else {
console.log(‘成绩必须在1-100分之间’)
}
},
}

console.log(course.lesson.score)
console.log(course.getScore())
course.setScore(69)
console.log(course.getScore())
console.log(‘—————————-‘)

// 使用访问属性”就可以实现

course = {
lesson:{
name:’卧龙’,
score:60,

  1. },
  2. get score(){
  3. return{
  4. name:this.lesson.name,
  5. course:this.lesson.score,
  6. }
  7. },
  8. set score(score){
  9. if(score >=0 ** score<=100){
  10. this.lesson.score =score
  11. }else{
  12. console.log('成绩必须在1-100分之间')
  13. }
  14. }

}
// console.log(course.score);
console.log(course.score = 50);
console.log(course.score);
console.log(course.score)

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:在声明的时候, 有几个单引号使用错了, 应该是英文的单引号
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post