-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path19-customObjectsAndFunctions.html
More file actions
34 lines (27 loc) · 1.1 KB
/
19-customObjectsAndFunctions.html
File metadata and controls
34 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Demo</title>
<script type="text/javascript">
// Working with custom functions and object properties
// constructor function (or blueprint) for the objects we want to create
var person = function (name, age) {
this.name = name;
this.age = age;
}
// creating an instance of an object
// the keyword `new` tells JS that we are creating the new instance of a variable.
var father = new person("Dale Sande", 40);
var daughter = new person("Zoe Sande", 7);
</script>
</head>
<body>
<script type="text/javascript">
// Let's call the properties of the objects we created
document.write("You are " + father.name + " and your age is " + father.age + "<br/>");
document.write("You are " + daughter.name + " and your age is " + daughter.age + "<br/>");
</script>
</body>
</html>