Why was "with" statement deprecated ?

This is more "an historical question", I ask here because it's kind of hard to search with throughout the net to get more informations about that, plus the spec isn't really extensive about why it has fallen into legacy.

I know it's forbidden in strict mode, considered bad practice, confusing, etc. but I'm actually wondering what were the motivations behind this ?

If you know about its "quirks", it looks quite like a normal feature, there are worse stuff present in the languages that have not been deprecated.

It's just a genuine question, I stumbled upon this because I wanted to try something like:

class A {
  test() {
    with(this) {
      console.log(test)
    }
  }
}

But ES classes are implicitely in strict mode from my understanding.

PS: I know it's possible to do in other ways (const {test} = this for example), the aim of the question is more about why it was almost "outed of the spec"

Thanks for your answers!

are a few examples i found with some quick google searches.

2 Likes

I was hoping for a more "official explanation" (like a comittee notes or discussions) but I guess the process was maybe not that standardized at that time (seems to be before ES5).

The links you provided mainly talk about the "quirks" I was referring too, but they don't per se justify the removal of this feature in strict mode and deprecation. Most of them just tell it's confusing and error-prone.

The first link does talk about being harder to optimize and that it may have been removed for security reasons according to Brendan Eich (but from a tweet), but these seems more that educated guesses rather from the author

Similar to the deprecated arguments.caller, with is both difficult to optimise and a refactoring hazard.

Yes, as you predict. The level of notes captured now is much more thorough than for the older versions.

1 Like

Those notes still exist, they just aren't as accessible as the more recent ones.

2 Likes

Yep there are notes for 2008/2009, leading up to ES5. They are mostly the agendas and some excerpts, rather than the full conversations.
I can’t admit to doing a full exhaustive search, so maybe there is a good archived document to reference there if someone has the time to scan through them.

2 Likes

I’m sure it would be very appreciated as well for someone to PR in the older notes to the tc39/notes repo ;-)

3 Likes