运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Object Constructors</h1> <p id="demo"></p> <script> // Constructor Function for Person Objects function Person(firstName,lastName,age,eyeColor) { this.firstName = firstName; this.lastName = lastName; this.age = age; this.eyeColor = eyeColor; } // Create a Person Object const myMother = new Person("Sally","Rally",48,"green"); Person.prototype.changeName = function (name) { this.lastName = name; } // Change Name myMother.changeName("Doe"); // Display Name document.getElementById("demo").innerHTML = "My mother's last name is " + myMother.lastName; </script> </body> </html>