x
1
2
<html>
3
<body>
4
5
<h2>JavaScript Object Constructors</h2>
6
7
<p id="demo"></p>
8
9
<script>
10
11
// Constructor function for Person objects
12
function Person(first, last, age, eye) {
13
this.firstName = first;
14
this.lastName = last;
15
this.age = age;
16
this.eyeColor = eye;
17
this.nationality = "English";
18
}
19
20
// Create 2 Person objects
21
const myFather = new Person("Hossam", "Mohamed", 50, "blue");
22
const myMother = new Person("Sally", "Rally", 48, "green");
23
24
// Display nationality
25
document.getElementById("demo").innerHTML =
26
"My father is " + myFather.nationality + ". My mother is " + myMother.nationality;
27
</script>
28
29
</body>
30
</html>