call bind and apply

by Rajdeep Chandra

JavaScript

/* declare an object name
 */
let name = {
  firstname: "Rajdeep",
  lastname: "Chandra"
}

//declare a method printmyname to print
let printMyName = function(hometown, state) {
  console.log(this.firstname + " " + this.lastname + " from " + hometown + "," + state)
}

// applying call method to the function which takes first argument which this refers to here name object and the extra parameter required
// call method is used for function borrowing
printMyName.call(name, "kolkata", "WB");