Could somebody please clarify why functions created by the Function constructor are assigned a name property with value "anonymous"? i.e., 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction:
39. Perform SetFunctionName(F, "anonymous").
This strikes me as odd and inconsistent. This is the only place in the spec where an anonymous function gets to have a name property, and usually Get(F, "name") would return "" (inherited from Function.prototype) for anonymous functions.
I suspect this might be another case of a web compatibility issue or web reality turning into spec but I couldn't find any information in that regard.
Similarly, I find it a bit strange that in the Function.prototype.toString revision proposal, the source text is synthesized as function anonymous(... when in fact the function is to be parsed without a BindingIdentifier.
My assumption is that it's to match legacy browser behavior.
Both Function.prototype.toString output and Function.name were implemented in browsers long before they were standardised, so yes, it鈥檚 just web reality with no compelling reason to change.
@woess does this satisfy your question / can we close this?
Thanks for the clarification, @ljharb and @claudepache. That answers my question.
Not very happy about this special case, but I agree there's no compelling reason to change.