-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathObject.js
More file actions
136 lines (88 loc) · 2.07 KB
/
Object.js
File metadata and controls
136 lines (88 loc) · 2.07 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// this
// call
// bind
// apply
// differenet method of object => some , every , object.keys
// constructor
// constructor function
// some es6 new update
let user ;
// handling error from developer side
try {
console.log(user.name);
} catch(error) {
console.log("this is my changes whatevere i do....")
}
console.log("Hey" ,user?.name)
if(user && user.name) {
console.log(user.name)
}
// global scope this => window
const userDetails = {
firstName: "Vishal",
lastName: "Sharma",
printName: function () {
console.log(this) // this context
console.log(this.firstName , this.lastName)
}
}
userDetails.printName();
const numbers = {
a:20,
b:30,
add:function() {
return function() {
console.log(this , "chill22")
}
},
multiply: function() {
// this ???
return ()=> {
console.log(this , "chill") // this ??
}
}
}
const numbers1 = {
firstName:20,
lastName:30,
printName:() => {
// ?? what is the value of this inside arrow function
console.log(this); // here is window ?
console.log("hEY" ,this.firstName , this.lastName)
}
}
numbers.multiply()();
numbers.add()();
// in the arrow this will alway point out to the its outer function or scope context
// here this mease gloabl scipe
const printContext = ()=> {
console.log("child" ,this)
}
const arrowFunction = (callback)=> {
const a= 40;
console.log(this);
callback();
}
arrowFunction(printContext)
console.log(this)
numbers.multiply();
function callme () {
console.log("Hey chill " , this) //
}
// BIND
var employeeDetailsXYZ = {
firstName: "Vishal" ,
lastName: "Sharma",
}
var employeeDetailsXYZ1= {
firstName: "Ashish" ,
lastName: "Rajput",
}
const printName = function() {
console.log(this)
console.log("Hey" ,this.lastName + this.firstName);
}
const printBindXYZ = printName.bind(employeeDetailsXYZ);
printBindXYZ();
const printBindXYZ1 = printName.bind(employeeDetailsXYZ1);
printBindXYZ1();