search

Home  >  Q&A  >  body text

javascript - ES6 . getter setter

class Person {

constructor (name, age) {
    this.name = name;
    this.age = age;
}
set name (name) {
    console.log("setter");
    this._name = name;
}
get name () {
    console.log("getter");
    return this._name;
}

// 加一个成员方法
sayName () {
    console.log(this.name);
}

}

The set get definition function here does not have the ES6 abbreviation of the previous set get. Why is the function here called by default during assignment

曾经蜡笔没有小新曾经蜡笔没有小新2833 days ago464

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-18 10:47:31

    Refer to this article/a/11...

    reply
    0
  • Cancelreply