BIND CALL AND APPLY IN JAVASCRIPT

const objectName = {
1st key: "value",
2nd key: "value"
}
const person = {
firstName: 'Asif Ur',
lastName: 'Rahman',
getFullName: function() { // this is called method
return this.firstName + ' ' + this.lastName;
},
}
const normalPerson = {
name: 'John',
salary: 1200,
chargeSalary: function (amount, tips, tax){
return this.salary = this.salary - amount - tips - tax;
}
}
const chargeNormalPerson = normalPerson.chargeSalary(500,500,500); console.log(chargeNormalPerson); // result :11500 or console.log(normalPerson.salary);// result :11500
const heroPerson ={
name: 'Hero',
salary: 5000
}
heroChargeSalary(300,100,100);
console.log(heroPerson.salary)// result :4500
normalPerson.chargeSalary.call (heroPerson, 300,100,100);
console.log(heroPerson.salary);// result :4500
normalPerson.chargeSalary.apply (heroPerson, [300,100,100]);
console.log(heroPerson.salary);// result :4500

--

--

Hi ! I am Asif. A full time web developer. Technical Course Writer & Campus Ambassador at Programming Hero || Web Developer at OmniGo || MERN Stack Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Asif Ur Rahman

Asif Ur Rahman

Hi ! I am Asif. A full time web developer. Technical Course Writer & Campus Ambassador at Programming Hero || Web Developer at OmniGo || MERN Stack Developer