forked from learning-zone/javascript-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype.html
38 lines (34 loc) · 990 Bytes
/
prototype.html
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
<!DOCTYPE html>
<html>
<head>
<title>Prototype in JS</title>
</head>
<script>
/***
* JavaScript does not support multiple inheritance.
*
* Inheritance of property values occurs at run time by JavaScript searching
* the prototype chain of an object to find a value. Because an object has a
* single associated prototype, JavaScript cannot dynamically inherit from more
* than one prototype chain.
*
***/
// Example: Person Class
function PersonClass(name, address) {
this.name = name;
this.address = address;
}
PersonClass.prototype.message = function() {
//Using prototype to add new function to class Person
console.log(this.name + ' says Hello !');
};
function init() {
var Obj = new PersonClass('Pradeep', 'Bangalore'); //Person Object
console.log(Obj.message());
}
init(); //function call
</script>
<body>
Prototype in JavaScript
</body>
</html>