Funkcja JavaScript Apply ()
const person = {
name: "John Smith",
getNameAndAddress: function(city, country)
{
return this.name+city+country;
}
}
const personWithoutGet = {
name: "Jerry Smithers"}
console.log(person.getNameAndAddress.apply(personWithoutGet, ['Berlin','Germany']));
}
/*you can think of apply() as "stealing someone else's function to use."*/
/* victimBeingStolenFrom.functionName.call(theThief,[any additional parameters as elements in an array]) */
/*notice the second variable personWithoutGet does not have a getName function*/
/*the difference between call and apply is that call accepts additional parameters separately while apply (this A) accepts the parameters as an array*/
Javasper