-
Notifications
You must be signed in to change notification settings - Fork 1
/
ObjectMethods3.js
48 lines (39 loc) · 1.14 KB
/
ObjectMethods3.js
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
// Object Methods
// Object: Key: Value pairs
// Object literal syntax - literally writng the object content
const prasanna = {
firstName: 'Prasanna',
lastName: 'Mallisetty',
birthYear: 2000,
job: 'Automation Test Analyst',
friends: ['Michael', 'Peter', 'Steven'],
hasDriverLicense: true,
// calcAge: function (birthYear) {
// return 2040 - birthYear
// }
calcAge: function () {
console.log(this);
return 2040 - this.birthYear
}
};
// console.log(prasanna.calcAge(2000));
// console.log(prasanna['calcAge'](2010));
console.log(prasanna.calcAge());
const prasanna = {
firstName: 'Prasanna',
lastName: 'Mallisetty',
birthYear: 2000,
job: 'Automation Test Analyst',
friends: ['Michael', 'Peter', 'Steven'],
hasDriverLicense: true,
calcAge: function () {
this.age = 2040 - this.birthYear
return this.age
},
getSummary: function () {
return `${this.firstName} is a ${this.calcAge()}
- years old ${this.job}, and he has ${this.
hasDriverLicense ? 'a' : 'no'} driver's licence.`
}
}
console.log(prasanna.getSummary())