运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!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> </html>