I want to do exactly the same as this question but use the function as a constructor.
> function nameFunction(name, body) {
return {[name](...args) {return body(...args)}}[name]
}
> b = nameFunction('c', function () {})
[Function: c]
> typeof b
'function'
b
is a function, yet it is not a constructor:
> new b()
Uncaught TypeError: b is not a constructor
If done in the standard way, it is a constructor:
> b = function() {}
[Function: b]
> new b()
b {}
But the name is b, not c.
How can I build a constructor with the given name and not using eval?