-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththis.js
43 lines (35 loc) · 800 Bytes
/
this.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
// this is a keyword used with objects refers to the current used object.
// object binding
const person = {
fname : "Ahmed",
lastname : "Ali",
id : 1402,
my : function() {
return this.fname + " " + this.lastname;
}
};
person.my();
const person1 = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
const person2 = {
firstName:"John",
lastName: "Doe",
}
// Return "John Doe":
person1.fullName.call(person2);
// function binding another
const per = {
firstName:"John",
lastName: "Doe",
fullName: function () {
return console.log(this.firstName + " " + this.lastName);
}
}
const member = {
firstName:"Hege",
lastName: "Nilsen",
}
let fullName = per.fullName.bind(member);