JavaScript has gone from simple to complex. The author looks at the problem from another Angle.

  • JavaScript’s a mess — and that’s a good thing
  • Translator: Fundebug

To ensure readability, free translation rather than literal translation is used in this paper. In addition, the copyright of this article belongs to the original author, and translation is for study only.

JavaScript never removes old features, and new versions are always backward compatible. I wish we could clean up the old features that are repetitive, but there are so many benefits to being compatible. I’ll explain in this article.

1. Advantages of backward compatibility

  1. Migrating to a new language version is a breeze. For example, if you use ES6, none of the old code needs to be changed.
  • The ES module alone is difficult to adopt because it breaks backward compatibility.
  1. Versioning of code is avoided. If you allow some code to be “old” and some to be “new” :
  • Language engines and tools have become more complex
  • Developers need to be careful with different versions
  • You can no longer move code around (if the code base is mixed)

2. Some tips for handling JavaScript extensions

  • Teach and learn: You can just ignore old features, not only what they look like, but why do they need to know
  • Use Linter to assist code
  • Use Prettier to beautify code

3. A clean JavaScript

If you want to use a cleaner JavaScript, you can ignore a lot of old syntax. Here are some suggestions:

  • Var: Use let and const
  • Function: Use arrow functions and method definitions. Advantages: Easier to deal with this. (Specific information)
  • Promises: Use async functions only. You can’t avoid Promises completely.
  • Iteratively access objects: Use map
  • Loop: Avoid for-in, avoid for-if possible, and recommend for-of.
  • Rest parameters(… args)
  • Function.prototype. Apply () : spread operator(f(.. myArray))
  • Constructor: Use class
  • IIFEs(Call functions now): Uses block scope

4. To be determined

Typeof and Instanceof are so complex that I can’t suggest one replace the other. Beyond Typeof and Instanceof: simplifying Dynamic Type checks

5. Read more

  • Chapter: A JavaScript: Avoid versioning in ES6
  • Chapter: ES6 Core Features (which ES5 features are replaced by better ES6 features)
  • Chapter: Async functions
  • Blog: A different way to understand this in JavaScript

About Fundebug

Fundebug focuses on BUG monitoring of JavaScript, wechat mini programs and small games. Since its official launch on November 11, 2016, Fundebug has been serving for one and a half years and has handled over 500 million error events in total, which has been recognized by many well-known users. Fundebug supports mainstream front-end framework bug monitoring, welcome to experience!