This is a variation of How do I write a named arrow function in ES2015? question, though the specific aim is to name the function object in a way that would make it available for Chrome CPU profiler.
I have tried the following:
let unnamed;
unnamed = () => {
};
Object.defineProperty(unnamed, 'name', {
value: 'XXX'
});
Object.defineProperty(unnamed.constructor, 'name', {
value: 'YYY'
});
Object.defineProperty(unnamed, 'displayName', {
value: 'ZZZ'
});
console.log('unnamed.name', unnamed.name);
console.log('unnamed.constructor.name', unnamed.constructor.name);
console.log('unnamed.displayName', unnamed.displayName);
export default unnamed;
However, whatever I do, CPU profiler is showing it as (anonymous function)
.
Interestingly, if you throw an error, the stack trace uses displayName
property.