运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript</h1> <h2>The prototype Property</h2> <p>The prototype property allows you to add new properties and methods to existing objects.</p> <p>Add a salary to all employees:</p> <p id="demo"></p> <script> function employee(name, jobtitle, born) { this.name = name; this.jobtitle = jobtitle; this.born = born; } employee.prototype.salary = 2000; const fred = new employee("Fred Flintstone", "Caveman", 1970); document.getElementById("demo").innerHTML = fred.salary; </script> </body> </html>