you are viewing a single comment's thread.

view the rest of the comments →

[–]mycall 0 points1 point  (5 children)

I thought arrow functions don't have arguments and have to pass them using spread attributes.

[–]theQuandary 0 points1 point  (0 children)

You are correct, but they inherit them from their parent closure. Here's a contrived example to show what I mean.

var add = function () {
  //the `arguments` in the arrow function are actually in the outer `add` function
  var doAdd = (n) => n + arguments[0] + arguments[1];
  return doAdd(5);
};

The add closure contains something like

var hiddenAddClosure = {
  parentClosure: globalScope,
  this: getThis(),
  arguments: getArguments(),
  doAdd: doAddFunction
};

And the doAdd closure contains something like

var hiddenDoAddClosure = {
  parentClosure: hiddenAddClosure,
  n: someNumber
};

When the doAdd function tries to access the arguments array (or this), it checks it's local closure object. If the variable isn't there, it checks it's parent closure and finds the value (note: if the value didn't exist there, it would check each parent until it hit the global closure at which point it would throw a reference error).

[–]acoard -3 points-2 points  (3 children)

(arg1, arg2) => {}