New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are dynamically created functions named "anonymous"? #1211

Closed
woess opened this Issue May 30, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@woess
Contributor

woess commented May 30, 2018

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.

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb May 30, 2018

Member

My assumption is that it's to match legacy browser behavior.

Member

ljharb commented May 30, 2018

My assumption is that it's to match legacy browser behavior.

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

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.

Contributor

claudepache commented May 30, 2018

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.

@bmeck

This comment has been minimized.

Show comment
Hide comment
@bmeck

bmeck Jun 4, 2018

Member

@woess does this satisfy your question / can we close this?

Member

bmeck commented Jun 4, 2018

@woess does this satisfy your question / can we close this?

@ljharb ljharb added the question label Jun 4, 2018

@woess

This comment has been minimized.

Show comment
Hide comment
@woess

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.

Contributor

woess commented Jun 4, 2018

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.

@woess woess closed this Jun 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment