I think this example may make the difference clear. arguments
is an array like object that contains each of the arguments passed to a function.
Try running each of these lines on your favorite browser console.
var somefunction = function() { console.log(arguments); };
Your first example demonstrates defining a named function a
that closes around the named function somefunction
.
var a = function() { somefunction(); };
Your second example makes a reference, b
, directly to somefunction
. This makes invoking b
the same as invoking somefunction
.
var b = somefunction;
Now if you call each of these a
and b
with some arguments you will see the difference.
=> a('a', 1);
[]
=> b('a', 1);
['a', 1]
In the first case the arguments
object is empty. That's because the arguments that were passed to a
were not forwarded onto somefunction
.
In the second case the arguments are available to somefunction
, because some function is being called directly.
Here is how you could redefine a
so that it were functionally equivalent using apply
var a = function() { somefunction.apply(this, arguments); }
Running this at your console prints the argument array.
=> a('a', 1);
['a', 1]