-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOOPS.js
60 lines (47 loc) · 1.12 KB
/
OOPS.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
49
50
51
52
53
54
55
56
57
58
// Object literal is simply key:value pair
/*
// First Way to Create Object.
let bioData = {
myName : "Kuldeep Singh",
myAge :26,
getData : function(){
console.log(`My name is ${bioData.myName} and my Age is ${bioData.myAge}`);
}
}
console.log(bioData.myName);
console.log(bioData.myAge);
bioData.getData();
*/
let bioData = {
myName : "Kuldeep Singh",
myAge :26,
getData(){
console.log(`My name is ${bioData.myName} and my Age is ${bioData.myAge}`);
}
}
console.log(bioData.myName);
console.log(bioData.myAge);
bioData.getData();
let bio = {
myName : {
firstName : "Kuldeep",
secondName : "Singh",
},
myAge :26,
getData(){
console.log(`My name is ${bioData.myName} and my Age is ${bioData.myAge}`);
}
}
console.log(bio.myName);
console.log(bio.myName.firstName);
console.log(bio.myName.secondName);
// Example of this
console.log(this); // it refers to the current context and that is window global object
const obj = {
myAge : 30,
getMyAge(){
console.log(this);
console.log(this.myAge);
}
}
obj.getMyAge();