const person = {
name: "John Smith",
getNameAndAddress: function()
{
return this.name;
}
}
const personWithoutGet = {
name: "Jerry Smithers"}
console.log(person.getName.bind(personWithoutGet);
}
/*you can think of bind() apply() and call() ALL as "stealing someone else's function to use."*/
/* victimBeingStolenFrom.functionName.call(theThief) */
/*notice the second variable personWithoutGet does not have a getName function*/
const person = {
firstName:"John",
lastName: "Doe",
fullName: function () {
return this.firstName + " " + this.lastName;
}
}
const member = {
firstName:"Hege",
lastName: "Nilsen",
}
let fullName = person.fullName.bind(member);
var car = {
registrationNumber: "FT5142",
brand: "Benz",
displayDetails: function(){
console.log(this.registrationNumber+ " " + this.brand );
}
}
car.displayDetails();
var myCarDetails = car.displayDetails.bind(car);
myCarDetails();
var car = {
registrationNumber: "FT5142",
brand: "Benz",
displayDetails: function(ownerName){
console.log(ownerName + ", this is your car: " + this.registrationNumber+ " " + this.brand );
}
}
// car.displayDetails();
var myCarDetails = car.displayDetails.bind(car, "Raymund");
myCarDetails();
this.getView().addEventDelegate({
onBeforeFirstShow: function() {
// Some codes
}.bind(this)
});