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

3
  • Any object can be used as a this value, even null. Commented Feb 25, 2013 at 21:49
  • duplicate of why does array slice convert javascript arguments to array Commented Feb 25, 2013 at 22:06
  • arguments is an array-like object, containing a reference to each argument passed to the function. Commented Feb 25, 2013 at 22:07

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.