Is it possible to somehow set a name for anonymous functions?
There is no need to add function names to the namespace for anonymous functions but I would like to avo
You could do something like this with arrow functions, it works for me on Node.
const createTask = ([name, type = 'default']) => {
const fn = () => { ... }
Object.defineProperty(fn, 'name', {
value: name,
configurable: true,
})
return fn
}
MDN is somewhat misleading here:
You cannot change the name of a function, this property is read-only...
To change it, you could use Object.defineProperty() though.
This answer provides more details.