google / google/CodeCity

Editors should set anonymous function .name when appropriate

Open
#376 0 comments 0 reactions 0 assignees View on GitHub
core
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.