Nisha Callapplybind
Nisha Callapplybind
let employee = {
name:"sam",
age:38,
getDetails: function(sex){
console.log(this)
console.log(`${this.name} ${this.age} ${sex}`)
}
}
let customer = {
name:"sus",
age:34
}
// employee.getDetails()
// employee.getDetails.call(customer,"female");
// employee.getDetails.apply(customer,["female"]);
// ----------------------------------
// we can remove the getDetails() from employee object and put it outside
let customer = {
name:"sus",
age:34
}
getDetails.call(employee)
getDetails.call(customer,"female");
getDetails.apply(customer,["female"]);
// ---------------------------------- bind
let customer = {
name:"sus",
age:34
}
let x = getDetails.bind(employee);
x("male") // here we pass the arguments in comma not array type
// Ex:- we need to create a button and on the click of that details will populate
in console