Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Class Static Methods</h2>
<p>To use the "mycar" object inside the static method, you can send it as parameter.</p>
<p id="demo"></p>
<script>
class Car {
  constructor(brand) {
    this.carname = brand;
  }
  static hello(x) {
    return "Hello " + x.carname;
  }
}
mycar = new Car("Ford");
document.getElementById("demo").innerHTML = Car.hello(mycar);
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_class_static2 by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 21 Dec 2022 17:39:07 GMT -->
</html>