ES6 Module arrow function exports don't retain their name

Viewed 1184

Why do exported arrow functions NOT retain their name and is there a way to have them do so?

Give an ES6 Module like below:

myModule.js

export function doSomeWork1() {
}
export const doSomeWork2 = () => {
};

If I then import them into another file like so the exported function retains its name while the arrow function does not.

example.js

import { doSomeWork1, doSomeWork2 } from './myModule';
console.log('doSomeWork1...');
console.log(doSomeWork1);
console.log(doSomeWork1.name); // name is retained    
console.log('doSomeWork2...');
console.log(doSomeWork2);
console.log(doSomeWork2.name); // name is NOT retained

output:

doSomeWork1...
[Function: doSomeWork1]
doSomeWork1
doSomeWork2...
[Function]

If I were to declare an arrow function in an ES6 Module without exporting it and print it out directly in that file it does retain it's name.

myModule.js

const doSomeWork3 = () => {
};
console.log('doSomeWork3...');
console.log(doSomeWork3);
console.log(doSomeWork3.name); // name is retained 

output:

doSomeWork3...
[Function: doSomeWork3]
doSomeWork3
1 Answers
Related