-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrototype.html
More file actions
47 lines (37 loc) · 1.27 KB
/
Prototype.html
File metadata and controls
47 lines (37 loc) · 1.27 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
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prototype</title>
</head>
<body>
<script>
function Person(firstName, lastName) {
// How to create property
this.firstName = firstName;
this.lastName = lastName;
// How to Create Method
this.sayHello = function (name) {
console.info(`Hello ${name}, my name ${this.firstName}`);
}
}
// How to create prototype to all variabel
Person.prototype.sayRun = function () {
console.info(`${this.firstName} is running`);
}
// Memanggil Class / Construct Func
const adrian = new Person("Adriana", "Monica"); //how to calling construct function
adrian.sayBye = function () { //How to create prototype to just one variebel
console.info(`Good Bye`);
}
const saskia = new Person("Sakia", "Nov"); //how to calling construct function
// Memanggil method
console.info(adrian)
console.info(saskia)
// Calling prototype
adrian.sayRun()
</script>
</body>
</html>