Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Object Constructors</h1> <p id="demo"></p> <script> // Constructor Function for Person objects function Person(first, last, age, eye) { this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eye; this.fullName = function() { return this.firstName + " " + this.lastName }; } // Create a Person object const myFather = new Person("John", "Doe", 50, "blue"); // Display full name document.getElementById("demo").innerHTML = "My father is " + myFather.fullName(); </script> </body> </html>