Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Difference between call() and apply()

#call() and apply()

The main difference between call() and apply() is that call() accepts an argument list, while apply() accepts a single array of arguments.

Good links: https://medium.com/the-javascript-collection/9e6122cde639 http://hangar.runway7.net/javascript/difference-call-apply

  • call() - Immediately invokes a function in the context of a specified ‘this’ object. ‘call’ requires at least one argument to specify the context, and any additional arguments will be passed as a series of parameters to the function being called.

  • Usage: call() is useful when the arguments of a function are already known, such as when you want to invoke a function on each item in a collection.

  • apply()-expects the second argument to be an array that it unpacks as arguments for the called function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.