Bradford
Bradford

Reputation: 4193

How to get anonymous function to be named in Chrome Timeline?

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.

Slow

Upvotes: 2

Views: 736

Answers (2)

Barmar
Barmar

Reputation: 782407

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.

Upvotes: 1

Gavriel
Gavriel

Reputation: 19237

Don't use lambda functions in your code. Instead of:

async(function(){});

write:

function withName(){};
async(withName);

Upvotes: 2

Related Questions