Getters and Setters in a function (javascript)

后端 未结 3 508
悲&欢浪女
悲&欢浪女 2021-01-12 16:08

When using get in an object like this, get works:

var people = {
  name: \"Alex\",
  get say         


        
3条回答
  •  逝去的感伤
    2021-01-12 16:27

    For example, use this:

    function People2() {
      this.name = "Mike";
      this.__defineGetter__("sayHi", function() {
        return `Hi, ${this.name}!`;
      });
    };
    

提交回复
热议问题