call, apply and bind
call and apply run a function with a chosen this. bind returns a new function with this and arguments fixed.
Example
function hi(greeting) { return greeting + " " + this.name; }
const user = { name: "Ada" };
console.log(hi.call(user, "Hello"), hi.apply(user, ["Hi"]));
const bound = hi.bind(user, "Hey");
console.log(bound());Exercise
Fix this for later.
fn.(obj)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.