-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12-57. Prototype Implementation.js
More file actions
108 lines (76 loc) · 2.2 KB
/
Copy path12-57. Prototype Implementation.js
File metadata and controls
108 lines (76 loc) · 2.2 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* that's how you can pass the properties and methods inside the prototype,
that it's available in all instances. */
var person ={
name: 'Ayush',
yearofBirth: 2003,
job: 'Student'
}
function Person(pName, pYearofBirth, pJob){
this.name = pName;
this.yearofBirth = pYearofBirth;
this.job = pJob;
this.calculateAge = function(){
console.log(2022 - this.yearofBirth)
}
}
Person.prototype.calculateAge = function(){
console.log(2019 - this.yearofBirth)
}
var john = new Person('John', 2003, 'Student')
john.calculateAge();
var claire = new Person('Claire', 1994, 'Doctore')
claire.calculateAge();
console.log(john)
console.log(claire)
//---------------------------------------------------------
var person ={
name: 'Ayush',
yearofBirth: 2003,
job: 'Student'
}
function Person(pName, pYearofBirth, pJob){
this.name = pName;
this.yearofBirth = pYearofBirth;
this.job = pJob;
this.calculateAge = function(){
console.log(2022 - this.yearofBirth)
}
}
Person.prototype.calculateAge = function(){
console.log(2019 - this.yearofBirth)
}
Person.prototype.lastName = "Mishra"
var john = new Person('John', 2003, 'Student')
john.calculateAge();
var claire = new Person('Claire', 1994, 'Doctore')
claire.calculateAge();
console.log(john)
console.log(claire)
console.log(john.lastName)
// Methods to set data :
var person ={
name: 'Ayush',
yearofBirth: 2003,
job: 'Student'
}
function Person(pName, pYearofBirth, pJob){
this.name = pName;
this.yearofBirth = pYearofBirth;
this.job = pJob;
this.calculateAge = function(){
console.log(2022 - this.yearofBirth)
}
}
Person.prototype.calculateAge = function(){
console.log('For => ' + this.name , 2019 - this.yearofBirth)
}
Person.prototype.updateYearofBirth = function(birthYear){
this.yearofBirth = birthYear
}
Person.prototype.lastName = "Mishra"
var john = new Person('John', 2003, 'Student')
john.calculateAge();
john.updateYearofBirth(2001);
john.calculateAge();
var claire = new Person('Claire', 1994, 'Doctore')
claire.calculateAge();