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.name = function() {
18
return this.firstName + " " + this.lastName
19
};
20
}
21
22
// Create a Person object
23
const myFather = new Person("Mahmoud", "adel", 50, "blue");
24
25
// Display full name
26
document.getElementById("demo").innerHTML =
27
"My father is " + myFather.name();
28
29
</script>
30
31
</body>
32
</html>