I’ve been working with JavaScript for over a decade now, and one thing that still confuses many devs early on is the difference between call
and apply
. At their core, both let you invoke a function and set its this
context — super useful for borrowing methods or controlling context.
Now, here’s the key difference in the javascript apply vs.call discussion:
-
call
takes arguments one by one:func.call(thisArg, arg1, arg2, ...)
-
apply
takes arguments as an array:func.apply(thisArg, [arg1, arg2, ...])
So if you already have your arguments in an array, apply
just saves you that little extra step.