Skip to content

Instantly share code, notes, and snippets.

@rbuckton
Created January 28, 2020 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbuckton/0100e6df3a687366f8a3f44c92c7cd5e to your computer and use it in GitHub Desktop.
Save rbuckton/0100e6df3a687366f8a3f44c92c7cd5e to your computer and use it in GitHub Desktop.
ECMAScript Strawperson: nameof operator

Purpose:

  • Primarily for developer tooling, such as for "rename" refactoring.

Syntax:

nameof IdentifierName

Examples:

// operand must be an IdentifierName
const obj = {};
nameof obj; // "obj"

// The IdentifierName does not need to be an initialized declaration
nameof C; // "C"
class C {}

// In fact, the IdentifierName doesn't even need to be a valid declaration
nameof DoesNotExist; // "DoesNotExist"

// Any valid IdentifierName is permitted
nameof package; // "package" (future reserved word)
nameof this; // "this"
nameof function; // "function"
nameof delete; // "delete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment