This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.



Smartphone icons created by Freepik - Flaticon

JS Class Static Methods

To use the "myCar" object inside the static method, you can send it as parameter.

class Car {
  constructor(name) {
    this.name = name;
  }
  static hello(x) {
    return "Hello " + x.name;
  }
}

const myCar = new Car("Ford");
document.getElementById("demo").innerHTML = Car.hello(myCar);