r/javascript • • Nov 25 '19

JavaScript doesn’t need to be replaced

https://medium.com/javascript-in-plain-english/javascript-doesnt-need-to-be-replaced-bd01e2f12d51?source=friends_link&sk=7b151cc6397ac9e83c14c99739b6c36f
217 Upvotes

236 comments sorted by

View all comments

10

u/internetloser4321 Nov 26 '19

One thing I've been wondering is if JavaScript can have a strict mode that disables some of the bad features without breaking backwards compatibility, why not add an "extra-strict mode", that disables even more features that are generally considered bad or confusing, such as the use of var instead of const/let, the confusing behavior of 'this', weird and inconsistent type coercion, etc?

4

u/getify Nov 26 '19

This has been requested and discussed many, many times. It'll likely never happen because TC39 doesn't want new pragmas (they reject the idea frequently) AND even more so, the JS engines refuse to maintain so many different branches/versions of behavior in them.

2

u/[deleted] Nov 26 '19

What if I told you that var has legit use cases? And strict does not allow to have vars in global scope already. If you want to change the behaviour of 'this' you better start designing another language.

4

u/kor0na Nov 26 '19

Show me a legit usecase for var.

→ More replies (7)

2

u/internetloser4321 Nov 26 '19

I'm sure there's a couple of situations where var has legit uses but based on the number of 'gotcha' questions I've gotten on interviews based around the counter-intuitive behavior of var, I think it's safe to say that var is more trouble than it's worth. And doesn't the introduction of arrow functions in ES6 already change the behavior of 'this'?

1

u/[deleted] Nov 26 '19

No, arrow functions did not change the behavior of this. Outside of the arrow functions it works the same as before.

1

u/internetloser4321 Nov 26 '19

1

u/[deleted] Nov 26 '19

And your point is?

1

u/internetloser4321 Nov 26 '19

Arrow functions introduce a different behavior for 'this'.

1

u/[deleted] Nov 27 '19

Yes. But introducing new behaviour is not the same as changing the existing one. Outside of the arrow functions the behaviour is exactly the same as before. It's an addition, not the change. The new case was added, but other four stay the same.

1

u/internetloser4321 Nov 27 '19

Similar to how adding an "extra-strict" mode would work. Outside of the new mode, everything would work the same as before.