Infer name of anonymous callback function based on argument name

Marius Gundersen gundersen at
Sun Jun 4 18:39:43 UTC 2017

As of ES2015 functions defined without an explicit name get their name from
the variable or property they are assigned to, which is great for
debugging. I want to propose another way a function can get it's name,
which is when anonymous functions (or arrow functions) are defined as
parameter to a function. For example:

    function flatMap(list, mapFunc){
      return [].concat(;

    flatMap([1,2,3], x => throw new Error('oh noes'))

In this example the stack trace will not have a name for the lambda that
throws an error. It would be useful if it could take the name of the
flatmap argument (mapFunc).

Marius Gundersen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list