The Chrome Developer Tools Timeline shows "(anonymous function)" for all of the code that's running slow and so I can't figure out what's going on. Is there a trick to getting these named? It also won't allow me to jump to the source of these anonymous functions. I'm using ES6 w/ arrow functions and babel.
Asked
Active
Viewed 711 times
2
-
Just [name it](http://stackoverflow.com/questions/15336347/why-use-named-function-expressions)? Alternatively, assign it to a variable or property when creating the function. – Bergi Jan 29 '16 at 01:41
2 Answers
2
Don't use lambda functions in your code. Instead of:
async(function(){});
write:
function withName(){};
async(withName);

Gavriel
- 18,880
- 12
- 68
- 105
1
Use a named function expression:
function call_callback(cb) {
cb();
}
function doit() {
call_callback(function not_anonymous() {
alert("done");
});
}
<button onclick="doit()">Click me</button>
The scope of the name is only the body of the function, but it shows up in the debugger.

Barmar
- 741,623
- 53
- 500
- 612