If "this" wasn't a mistake and a loaded footgun, then why did Brendan Eich himself literally say that "dynamic this binding is an oft-fired footgun" in the "Rationale" section of his original fat "Arrow Functions" proposal?
And why did Douglas Crockford say "this" was "horrible", and that ES5/strict mode was "much less wrong than binding the global object, but is still not right"?
And why is "this" always showing up as #1 in the lists of "10 Most Common JavaScript Mistakes"?
https://www.toptal.com/javascript/10-most-common-javascript-...
>Buggy JavaScript Code: The 10 Most Common Mistakes JavaScript Developers Make
>Common Mistake #1: Incorrect references to this
>I once heard a comedian say:
>I’m not really here, because what’s here, besides there, without the ‘t’?
>That joke in many ways characterizes the type of confusion that often exists for developers regarding JavaScript’s this keyword. I mean, is this really this, or is it something else entirely? Or is it undefined?
>As JavaScript coding techniques and design patterns have become increasingly sophisticated over the years, there’s been a corresponding increase in the proliferation of self-referencing scopes within callbacks and closures, which are a fairly common source of “this/that confusion”.
https://javascriptissexy.com/understand-javascripts-this-wit...
>Understand JavaScript’s “this” With Clarity, and Master It
>(Also learn all the scenarios when this is most misunderstood.)
>The this keyword in JavaScript confuses new and seasoned JavaScript developers alike. This article aims to elucidate this in its entirety. By the time we make it through this article, this will be one part of JavaScript we never have to worry about again. We will understand how to use this correctly in every scenario, including the ticklish situations where it usually proves most elusive.
https://dev.to/joelnet/rethinking-javascript-the-complete-el...
>Rethinking JavaScript: The complete elimination and eradication of JavaScript's this.
>If this is so difficult to reason about, why don't we just stop using it? Seriously. Why. don't. we. just. stop. using. it.?
>If you have read How I rediscovered my love for JavaScript after throwing 90% of it in the trash, then you won't be surprised when I say I am throwing this away. this is gone. goodbye. this won't be missed.
>With functional JavaScript, you will almost never see this. I say almost never because even though your code doesn't contain this, you have little control over 3rd party libraries. Popular libraries like React, jQuery, eventemitter2 and many others will force this down your throat.
>Here are some examples of how libraries force us to use this.
[...]
https://softwareengineering.stackexchange.com/questions/3060...
>Why doesn't ES6 have thin-arrow functions?
>See the proposal to add arrow functions:
http://wiki.ecmascript.org/doku.php?id=harmony:arrow_functio...
[That link is broken but this one works:
https://tc39wiki.calculist.org/es6/arrow-functions/ ]
>What it says is:
>However, we don’t want CoffeeScript’s ->, it’s confusing to have two arrows and dynamic this binding is an oft-fired footgun.
That's right: the original fat arrow proposal championed by Brendan Eich himself literally called "dynamic this binding" an "oft-fired footgun", citing it as the rationale to justify the design of fat arrow functions. That comes directly from the horse's mouth. Do you really disagree with Brendan Eich on that point?
More interesting discussion about this and that:
Douglas Crockford on Fat Arrow Functions in JavaScript (yuiblog.com)
https://news.ycombinator.com/item?id=3780367
What is the meaning of this?
https://yuiblog.com/blog/2012/03/30/what-is-the-meaning-of-t...
>JavaScript is an amalgam of good parts and bad parts. Its best parts came from Self (prototypes) and Scheme (lexically scoped nested functions). But the interaction of those two very good parts produced some bad parts.
>When a function is called with the function invocation pattern, its this is not bound to the outer function's this as we would hope, but is instead bound to the global object, which is horrible. (ES5/strict binds the inner function's this to undefined, which is much less wrong than binding the global object, but is still not right.) The workarounds for this include the use of bind functions and riddles like
>var that = this;
I could go on. There are literally THOUSANDS of blog posts by people who got screwed by "this", and then posted about it to warn other people not to make the same mistake they did.