-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallApply.js
More file actions
51 lines (43 loc) Β· 1.28 KB
/
callApply.js
File metadata and controls
51 lines (43 loc) Β· 1.28 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
// Hazrat Ali
// University Of Scholars
const normalPerson = {
firstName: 'Rahim',
lastName: 'Uddin',
salary: 15000,
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;
}
}
// call apply js
const heroPerson = {
firstName: 'Hero',
lastName: 'Balam',
salary:25000
}
const friendlyPerson = {
firstName: 'Hero',
lastName: 'Golam',
salary:25000
}
normalPerson.chargeBill();
const heroChargeBill = normalPerson.chargeBill.bind(heroPerson);
heroChargeBill(2000);
heroChargeBill(3000);
console.log(heroPerson.salary);
console.log(normalPerson.salary);
const friendlyChargeBill = normalPerson.chargeBill.bind(friendlyPerson);
friendlyChargeBill(1500);
normalPerson.chargeBill.call(heroPerson, 900, 100, 10);
normalPerson.chargeBill.call(heroPerson, 3000, 300, 30);
console.log(heroPerson.salary);
normalPerson.chargeBill.call(friendlyPerson, 5000, 500, 50);
console.log(friendlyPerson.salary);
console.log(normalPerson.salary);
normalPerson.chargeBill.apply(heroPerson, [3000, 300, 30]);
normalPerson.chargeBill.apply(heroPerson, [4000, 400, 40])
console.log(heroPerson.salary);