-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply-method.js
More file actions
38 lines (32 loc) · 815 Bytes
/
apply-method.js
File metadata and controls
38 lines (32 loc) · 815 Bytes
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
//! apply() is same as call() but it only takes two arguments. 2nd argument is for function arguments as an array.
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();
message.email.msg.apply(message);
console.log("---------------------");
let zakir = {
fullName: "Zakir Hossian",
dob: 1994,
age: function (currentYear, msg) {
console.log(
msg + this.fullName + " is " + (currentYear - this.dob) + " years old"
);
},
};
zakir.age(2021, "Congratulations! ");
let shuvo = {
fullName: "Shuvo Islam",
dob: 1998,
};
zakir.age.apply(shuvo, [2020, "Congrats! "]);
console.log("---------------------");