Skip to content

Instantly share code, notes, and snippets.

@limianwang
Created August 5, 2015 21:42
Show Gist options
  • Save limianwang/48775b0e74f24d8981a9 to your computer and use it in GitHub Desktop.
Save limianwang/48775b0e74f24d8981a9 to your computer and use it in GitHub Desktop.
Apply VS Call

While starting at my new job, I have heard constantly the question for the difference between Function.apply and Function.call.

Fundamentally, they are equal. Nothing is different in what happens to the function itself. The difference is, though, about how the function will be called.

Function.prototype.apply expects and array of arguments, while Function.prototype.call expects a list/component for the arguments.

function test(a, b, c) {
  console.log(this); // scope
  console.log(Array.prototype.slice.call(arguments));
}

test.call(null, 1, 2, 3);
test.apply(null, [1, 2, 3]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment