W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 类</h1> <p>如何使用 JavaScript 类。</p> <p id="demo"></p> <script> class Car { constructor(name, year) { this.name = name; this.year = year; } } const myCar = new Car("Ford", 2014); document.getElementById("demo").innerHTML = myCar.name + " " + myCar.year; </script> </body> </html>