Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Difference between call apply and bind

Hi, I'm looking for someone to help me understand the difference between these functions in JS. I understand that call and apply allow you to set the context of 'this', only difference is how the arguments are supplied. Does bind do the same thing (with arguments provided like apply), but is for 'reusable' functions that aren't anonymous/created at runtime?

Yvonne Wood

1 Answer

So you seem to understand the different between call and apply, one takes a list of arguments and one takes an array that contains the arguments. Bind returns a new function that is bound to a separate 'this' value.

Call and apply invoke a function on a different 'this' value with the supplied arguments where as bind returns a new function that happens to be assigned a different this value.

I hope that helps.