Newsletter
Newsletter

Difference between Call, Bind & Apply

Scroll down
Subhash Yadav
Subhash Yadav
I`m
  • Total Years of Exp
    8+
  • Residence:
    Bangalore, INDIA
  • Talk On
    +91 94 350 39 305
  • Write On
    subhashyadav.one@gmail.com

September 23, 2023

14:32

admin

Call:
var emp1 = {firstName: “Subhash”, lastName: “Yadav”};
var emp2 = {firstName: “Nagina”, lastName: “Yadav”};
function invite(greeting1, greeting2) { console.log(greeting1 + ‘ ‘ + this.firstName + ‘ ‘ + this.lastName + ‘, ‘ + greeting2);
}
invite.call(emp1, ‘Hello’, ‘how are you’);
invite.call(emp2, ‘Hello’, ‘how are you’);


Bind:
var emp1 = {firstName: “Subhash”, lastName: “Suman”};
var emp2 = {firstName: “Kanchan”, lastName: “Yadav”};

function invite(arg1, arg2) {
console.log(arg1 + ‘ ‘ + this.firstName + ‘ ‘ + this.lastName + ‘, ‘ + arg2);
}
var emp1B = invite.bind(emp1);
var emp2B = invite.bind(emp2);
emp1B(‘Hello’, ‘how are you!!’);
emp2B(‘Hello’, ‘where are you!!’);


Apply:
var emp1 = {firstName: “Suman”, lastName: “Subhash”};
var emp2 = {firstName: “Yadav”, lastName: “Kanchan”};

function invite(greeting1, greeting2) {
console.log(greeting1 + ‘ ‘ + this.firstName + ‘ ‘ + this.lastName + ‘, ‘ + greeting2 + ‘!!’ );
}

invite.apply(emp1, [‘Hello’, ‘how are you’]);
invite.apply(emp2, [‘Hello’, ‘how are you’]);

Posted in Design, Events, TechnologyTags:
Write a comment
© 2024 All Rights Reserved.
Email: info@subhashyadav.com
Write me a message
Write me a message

    * I promise the confidentiality of your personal information