-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththis-in-objects.js
62 lines (53 loc) · 1.11 KB
/
this-in-objects.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
59
60
61
62
let id = 50;
let user = {
id: 49,
userName: "Rakib",
info: function () {
console.log(this); //!refers to the object
// console.log(`User ID: ${this.id}`);
// console.log(`User name: ${this.userName}`);
},
};
console.log(id);
user.info();
console.log("---------------------");
let message = {
type: "email",
to: "labib",
from: "pain",
email: {
type: "Electronic Mail",
subject: "study",
msg: function () {
console.log(`Message received as ${this.type}`);
},
},
};
message.email.msg();
console.log("---------------------");
let ladder = {
step: 0,
up() {
this.step++;
return this;
},
down() {
this.step--;
return this;
},
showStep: function () {
console.log(`Current Step: ${this.step}`); //shows the current step
return this;
},
};
// ladder.up();
// ladder.up();
// ladder.down();
// ladder.up();
// ladder.showStep();
console.log("---------------------");
//! make calls chainable
// ladder.up().up().down().showStep();
console.log("---------------------");
ladder.up().up().down().up().down().showStep();
ladder.up().up().showStep();