What do you think about a C# 6 like nameof() expression for

Ron Buckton Ron.Buckton at microsoft.com
Sat Jun 15 23:16:36 UTC 2019


```
const x = nameof y
const y = 1;
```

`x` would have the value “y”. It would not matter if `y` were initialized or had yet been reached during execution. It does not deviate from the purpose of `let` or `const`, because you are not accessing the value of the identifier.

Also consider that this is legal ECMAScript in a module:

```
export { y }
const y = 1;
```

The binding for `y` exists within the same block scope, it just has not yet been initialized. Exporting it via `export { y }`, closing over it via `() => y`, or accessing it via `nameof y` would all be the same. In all three cases you are accessing the *binding* of `y`, not the *value* of `y`. Even in the `() => y` case, you don’t access the *value* of `y` until you execute the function.

From: guest271314 <guest271314 at gmail.com>
Sent: Saturday, June 15, 2019 3:57 PM
To: Ron Buckton <Ron.Buckton at microsoft.com>
Cc: es-discuss at mozilla.org
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

> Sorry, I meant to say “not entirely correct”.

You have not yet confirmed if in fact the expected output is referencing a variable declared using ```const``` on the current line _before_ initialization _on the next line_.

That example appears to deviate from the purpose and usage of ```const```, beyond the scope of ```nameof```, and if were implemented, a ```ReferenceError``` should _not_ be thrown when a ```const``` variable that has yet to be initialized _on the next line_ is referred to _on the current line_?

Aside from that example, the code which essentially already implements ```nameof``` should be able to be found in the code which implements ```ReferenceError``` relevant to ```const```.

On Sat, Jun 15, 2019 at 10:47 PM Ron Buckton <Ron.Buckton at microsoft.com<mailto:Ron.Buckton at microsoft.com>> wrote:
Sorry, I meant to say “not entirely correct”.

From: Ron Buckton
Sent: Saturday, June 15, 2019 3:03 PM
To: guest271314 <guest271314 at gmail.com<mailto:guest271314 at gmail.com>>
Cc: es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>
Subject: RE: Re: What do you think about a C# 6 like nameof() expression for

> At that point in the example code the identifer ```y``` does not exist.

That is not entirely incorrect. The identifier `y` exists, but its binding has not been initialized, otherwise you couldn’t refer to y in this case:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190615/c078818d/attachment-0001.html>


More information about the es-discuss mailing list