Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upWhy are dynamically created functions named "anonymous"? #1211
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
My assumption is that it's to match legacy browser behavior. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
May 30, 2018
Contributor
Both Function.prototype.toString output and Function.name were implemented in browsers long before they were standardised, so yes, it’s just web reality with no compelling reason to change.
|
Both |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
@woess does this satisfy your question / can we close this? |
ljharb
added
the
question
label
Jun 4, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
woess
Jun 4, 2018
Contributor
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.
|
Thanks for the clarification, @ljharb and @claudepache. That answers my question. |
woess commentedMay 30, 2018
•
edited
Could somebody please clarify why functions created by the Function constructor are assigned a
nameproperty 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 fromFunction.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.