Feature Collection Babel arrow in ES5

Using Babel I noticed something strange.

Should not const app = () => {}be equalvar app = function() {}

Babylon returns var app = function app() {}.

+4
source share
1 answer

No, babel is correct because the arrow function assigned to var should theoretically have a name property equivalent to the name of this var to help in stack tracking and reflection. See this link for more details . A brief summary in case it is out of date:

The function name property is created at the time of declaration. The name property of the function expression is derived from the name binding:

var foo = function() {};
console.log(foo.name); // foo

Arrow functions have the same behavior:

var foo = () => {};
console.log(foo.name); // foo

, ES 2015/ES 6 babel function

var foo = function foo() {}; // notice it function *foo* now

.

+4

Source: https://habr.com/ru/post/1681366/


All Articles