0 points

getter method javascript - Google Search


dashboard

Mon Aug 10 2020 21:09:39 GMT+0000 (UTC)

Posted by @ludaley #javascript

class Car {
  constructor(brand) {
    this.carname = brand;
  }
  get cnam() {
    return this.carname;
  }
  set cnam(x) {
    this.carname = x;
  }
}

mycar = new Car("Ford");

document.getElementById("demo").innerHTML = mycar.cnam; //"Ford"
content_copy Copy

https://www.google.com/search?q=getter method javascript