1

Here is _.extend from underscore.

  // Extend a given object with all the properties in passed-in object(s).
  _.extend = function(obj) {
    each(slice.call(arguments, 1), function(source) {
      if (source) {
        for (var prop in source) {
          obj[prop] = source[prop];
        }
      }
    });
    return obj;
  };

The function call expects a this value followed by a list of arguments.

If the only argument passed is '1', then slice will return an array omitting the first item.

However, how can arguments be used as a this value as defined my MDN.

MDN

call

slice

arguments

  • Any object can be used as a `this` value, even `null`. – Matt Ball Feb 25 '13 at 21:49
  • duplicate of [why does array slice convert javascript arguments to array](http://stackoverflow.com/questions/14327339/why-does-array-slice-convert-javascript-arguments-to-array) – Bergi Feb 25 '13 at 22:06
  • `arguments` is an array-like object, containing a reference to each argument passed to the function. – Felix Kling Feb 25 '13 at 22:07

3 Answers3

1

The same thing it always references, the arguments passed to the containing function.

1

Using arguments as the this value applies the function to arguments. It would be like doing arguments.slice(1), except you can't because arguments is technically not an array.

Andrew Kirkegaard
  • 1,676
  • 11
  • 13
0

I believe "this" is implied. Sometimes you have to "force" a fake list to apply to some Array prototypes else it won't work.

I might be misunderstanding your questions, if so - I apologize.

james emanon
  • 11,185
  • 11
  • 56
  • 97