I have the next task:
const person = {name: 'Arnold'};
function fn(salut, lastName) {
console.log(salut, this.name, lastName);
}
const bindName = bind(fn, person, 'Mr');
bindName('Helgov');
I have to write a function that prints: "Mr Arnold Helgov"
My realization of this task is the next function:
function bind(fn, person, salute) {
return (lastname) => {
return fn(salute, lastname);
}
}
But I have a problem here. My function prints only "Mr Helgov" and the name 'Arnold' is lost. How to solve this problem (maybe by using bind or apply or call)?