Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Official information on `arguments` in ES6 Arrow functions?

(() => console.log(arguments))(1,2,3);  // Chrome, FF, Node give "1,2,3" // Babel gives "arguments is not defined" from parent scope 

According to Babel (and from what I can tell initial TC39 recommendations), that is "invalid" as arrow functions should be using their parent scope for arguments. The only info I've been able to find that contradicts this is a single comment saying this was rejected by TC39, but I can't find anything to back this up.

Just looking for official docs here.

like image 522
Nobody Avatar asked Jun 19 '15 10:06

Nobody


People also ask

Can arrow functions have arguments?

Arrow functions do not have an arguments binding. However, they have access to the arguments object of the closest non-arrow parent function. Named and rest parameters are heavily relied upon to capture the arguments passed to arrow functions.

Do arrow functions always require an argument?

Arguments bindingArrow functions do not have an arguments binding.

What is an ES6 arrow function?

Arrow function is one of the features introduced in the ES6 version of JavaScript. It allows you to create functions in a cleaner way compared to regular functions. For example, This function // function expression let x = function(x, y) { return x * y; }


1 Answers

Chrome, FF, and node seem to be wrong here, Babel is correct:

Arrow functions do not have an own arguments binding in their scope; no arguments object is created when calling them.

looking for official docs here

Arrow function expressions evaluate to functions that have their [[ThisMode]] set to lexical, and when such are called the declaration instantiation does not create an arguments object. There is even a specifc note (18 a) stating that "Arrow functions never have an arguments objects.".

like image 189
Bergi Avatar answered Oct 18 '22 21:10

Bergi