Editors should set anonymous function .name when appropriate
- Dominant language
- JavaScript
- Stars
- 198
- Forks
- 38
- PR merge metrics
- No merged PRs in 30d
Description
When the server option `methodNames` is true, statements assigning anonymous function expressions to properties (e.g., `foo.bar = function(){}`) result in the function's `.name` property being set, just as statements assigning anonymous function expressions to variables (e.g., `foo = function() {}`) and object literals (e.g. `{bar: function() {}}`) always do.
Since the editors evaluate the value to be saved on its own (not in the context of an assignment statement, even though it might look that way to the user), `.name` is not set.
This should be fixed, so that saving an anonymous function to a variable always sets its `.name`, and saving one to a property sets its `.name` if `methodNames` is true. Since server options are not accessible to the database, the latter will require a trivial experiment:
```JS
var foo = {};
foo.bar = function() {}; // N.B.: must do this as a separate step.
var methodNames = Boolean(foo.bar.name)
```
Contributor guide
Assessment
This issue has not been assessed yet.