tc39 / proposal-static-class-features

The static parts of new class features, in a separate proposal
https://arai-a.github.io/ecma262-compare/?pr=1668
127 stars 27 forks source link

Should class body lexical function declarations create const bindings? #20

Closed allenwb closed 6 years ago

allenwb commented 6 years ago

I'm not really pushing this idea, but I thought it should at least be captured.

It would be easier for humans and machines to reason about what is going on in class bodies if the bindings created by class body level lexical function declarations were immutable.

This creates an inconsistency between the handling of class body function declarations and function declarations in other scopes. I'm pretty uncomfortable with that inconsistency. However, if we think that a class body is so different from other scoping context that declaration need some sort of special prefix then consistency concerns seems to be out the window, so why not make the binding immutable.

littledan commented 6 years ago

As much as I'd be happy to have as many things immutable as possible, it's hard for me to understand the intuition behind this particular context making function declarations becoming suddenly immutable. Even if there's a keyword to make things more obvious, I was expecting everything else to be the same.

ljharb commented 6 years ago

I think many people are surprised to find out that they’re mutable in the first place, tho. I’m always surprised when i rarely find code that mutates them.

littledan commented 6 years ago

This proposal ended up not including lexical bindings.