Facebook Pixel

Can you change this of an arrow function with call or bind in JavaScript?

No. Arrow functions inherit this from their lexical scope at definition time. call, apply, and bind cannot change an arrow's this. They can still pass arguments, but this stays the same.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in call, apply, and bind in JavaScript: A Complete Guide

call and apply invoke the function immediately with a specific this (call takes comma-separated args, apply takes an array). bind returns a new function with this permanently bound, to be called later.

Use call or apply. For example, Array.prototype.slice.call(arguments) borrows the slice method to convert the array-like arguments object into a real array.

Presetting some arguments of a function using bind. const add5 = add.bind(null, 5) creates a new function where the first argument is always 5. When called with (3, 2), it calls add(5, 3, 2).

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.