How can i create a function object in JavaScript with call Method

 const person = {

  fullName: function () {

    return this.firstName + " " + this.lastName;

  },

};


const person1 = {

  firstName: "Anand",

  lastName: "Chaudhary",

};


const person2 = {

  firstName: "Rahul",

  lastName: "Chaudhary",

};


const fullName=person.fullName.call(person2);

console.log(fullName)


const person = {

  fullName: function (location, exp) {

    return this.firstName + " " + this.lastName + " " + location + " " + exp;

  },

};


const person1 = {

  firstName: "Anand",

  lastName: "Chaudhary",

};


const person2 = {

  firstName: "Rahul",

  lastName: "Chaudhary",

};


const fullName = person.fullName.call(person1, "Gurugaon", "2 years");

console.log(fullName);






Post a Comment

0 Comments