Skip to content

Should class declarations contain a binding for class name in scope for the class? #4161

@overlookmotel

Description

@overlookmotel

Should class declarations contain a binding for class name in the scope for the class?

Klass in example below has 2 bindings - 1st at top level, 2nd within the class body.

class Klass {
    static tryWrite() {
        Klass = 123;
    }
}

const CopyOfKlass = Klass;

// Reassignment of `Klass` in top level scope succeeds
Klass = 123;
console.log(Klass); // Logs 123

// Reassignment of `Klass` within class fails.
// `TypeError: Assignment to constant variable at Klass.tryWrite`
CopyOfKlass.tryWrite();

The outer binding is reassignable, whereas the binding within the class is read-only.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions