-
Notifications
You must be signed in to change notification settings - Fork 0
/
objmethod-bind.js
43 lines (34 loc) · 916 Bytes
/
objmethod-bind.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
const normalPerson = {
firstName : "Saidul",
lastName : "Islam",
salary : 15000,
getFullName : function(){
console.log(this.firstName + " " + this.lastName);
},
chargeBill : function(amount){
this.salary = this.salary - amount
return this.salary
}
}
// normalPerson.chargeBill(3000);
// normalPerson.chargeBill(3000);
// console.log(normalPerson.salary);
const heroPerson = {
firstName : "Moni",
lastName : "Islam",
salary : 35000
}
const friendlyPerson = {
firstName : "Shymoli",
lastName : "Begum",
salary : 52000
}
//apply bind method
const heroChargeBill = normalPerson.chargeBill.bind(heroPerson)
heroChargeBill(5000)
heroChargeBill(4000)
console.log(heroPerson.salary);
//apply bind method
const friendlyChargeBill = normalPerson.chargeBill.bind(friendlyPerson)
friendlyChargeBill(2000)
console.log(friendlyPerson.salary);