On the awesomeness of fn.displayName

Malte Ubl
Malte Ubl
Nov 13, 2014 · 4 min read

No function in a framework stack trace should have a useless name.

With the most useless name of them all being: (anonymous function).

fn.displayName = “some string”

…and boom: suddenly whenever a debugger wanted to print out the name of “fn” it would say “some string” instead of “anonymous function”.

Encode the most important piece of context on the stack.

Take e.g. this example:

    Malte Ubl

    Written by

    Malte Ubl

    Tech lead of the AMP Project. JavaScript infrastructure at Google. Curator of @JSConfEU

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade