-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall.js
More file actions
37 lines (33 loc) · 870 Bytes
/
call.js
File metadata and controls
37 lines (33 loc) · 870 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
// difference between bind, call and apply:
const normalPerson = {
firstName: 'Rahim',
lastName: 'Khan',
salary: 12000,
getFullName: function(){
console.log(this.firstName, this.lastName);
},
chargeBill: function(amount, tips, tax){
console.log(this);
this.salary = this.salary - amount - tips - tax;
return this.salary;
}
}
// normalPerson.chargeBill(500);
// console.log(normalPerson.salary);
// For Call Structure
const heroPerson = {
firstName: 'balam',
lastName: 'khan',
salary: 500,
}
const friendlyPerson = {
firstName: 'kalam',
lastName: 'uddin',
salary: 300,
}
// For call (,)
// normalPerson.chargeBill.call(heroPerson, 250);
// console.log(heroPerson.salary);
// For apply (array)
normalPerson.chargeBill.apply(heroPerson, [100, 50, 25]);
console.log(heroPerson.salary);