47

Dear Javascript, "this" isn't working

 5 years ago
source link: https://www.tuicool.com/articles/hit/22yqAbV
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Dear Javascript,

NVNFZbu.jpg!webUVBJNfb.jpg!web

this isn’t working.

When we first met, I was so excited. You were fun and easy to get along with . I told all my friends you were Java. We hit it off. Slowly at first… actually, really slowly . You may not have had class , but at least you had standards . Things eventually got… asynchronous . Bandwidth was tight, but it still felt like we were on the same page. I will always remember the first time we loaded individual elements together, instead of complete pages. With some help , even Internet Explorer seemed to be on board.

We stayed up late at night, holding requests for what felt like hours. You took it to 4 billion places I never thought it could go. In my mind, you had no equal . People thoughtwe were crazy. I could hardly await to escape callback hell because with you, nothing was out of scope . We prototyped one great framework after the next, never stopping to wonder why.

Then you started to let yourself go. You changed a lot . You became harder to talk to, blocking requests and blaming CORS . We had to use strict rules for communicating. Sure, you got class , but somehow even that was not quite right . Now there are too many frameworks and we have to let some go .

Do not get me wrong, there were Good Parts . But I hardly recognize you in the browser anymore. You are a transpiled, minified, polyfilled version of your former self. Several versions later and this is still not working. It is just one broken, nested Promise after the next. I just don’t want any more arguments .

P.S. You are not Java. You never were Java .

I have been making and breaking websites for about a decade, right around the time XMLHttpRequest gained widespread support. I decided to write a “break-up letter” to Javascript as a means of exploring my frustration. Despite this letter, I do not categorically hate front-end frameworks or the Javascript ecosystem. It is actually a versatile language that is well-suited for event-driven programming and strives for rapid self-improvement.

It is no longer novel to include such dynamic features as a live clock or page view counter, so lately I have been exploring WebSockets, GraphQL, and WebAssembly. While the complexity of web development will undoubtedly continue to increase, I hope with them come improvements to user experience as significant as those Ajax offered a decade prior.

Follow me on LinkedIn · GitHub · Medium


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK