Home > front end >  How to differentiate between class get set and constructor attributes
How to differentiate between class get set and constructor attributes

Time:09-26

What is the hidden field(argument1), I'm getting in chrome console?

class ClassName {
  constructor(argument1) {
    this._argument1 = argument1;
  }

  get argument1() {
    return this._argument1   " by get method.";
  }

  set argument1(value) {
    if (value.length < 4) {
      console.log("Please provide name with more length.");
      return;
    }
    this._argument1 = value;
  }
}

let object1 = new ClassName("abcde");
console.info(object1);

Invoke property "getter"

  • Related