- Mastering Angular Components
- Gion Kunz
- 245字
- 2021-07-23 17:23:39
Classes
Classes were among one the most requested features in JavaScript, and I was one of the people voting for it. Well, coming from an OOP background and being used to organizing everything within classes, it was hard for me to let go. Although, after working with modern JavaScript for some time, you'll reduce their use to the bare minimum and to exactly what they are made for—inheritance.
Classes in ECMAScript 6 provide you with syntactic sugar to deal with prototypes, constructor functions, super calls, and object property definitions in a way that you have the illusion that JavaScript could be a class-based OOP language:
class Fruit {
constructor(name) { this.name = name; }
}
const apple = new Fruit('Apple');
As we learned in the previous topic about transpilers, ECMAScript 6 can be de-sugared to ECMAScript 5. Let's take a look at what a transpiler will produce from this simple example:
function Fruit(name) { this.name = name; }
var apple = new Fruit('Apple');
This simple example can easily be built using ECMAScript 5. However, once we use the more complex features of class-based object-oriented languages, the de-sugaring gets quite complicated.
ECMAScript 6 classes introduce simplified syntax to write class member functions (static functions), the use of the super keyword, and inheritance using the extends keyword.
If you would like to read more about the features in classes and ECMAScript 6, I highly recommend that you read the articles of Dr. Axel Rauschmayer (http://www.2ality.com/).
- C++黑客編程揭秘與防范
- 智能網聯汽車V2X與智能網聯設施I2X
- 物聯網網絡安全及應用
- Truffle Quick Start Guide
- Hands-On Industrial Internet of Things
- 走進物聯網
- 面向云平臺的物聯網多源異構信息融合方法
- 圖解手機元器件維修技巧
- Microsoft Dynamics CRM 2011 Applications(MB2-868) Certification Guide
- 物聯網長距離無線通信技術應用與開發
- Selenium WebDriver 3 Practical Guide
- 深入理解計算機網絡
- 精通SEO:100%網站流量提升密碼
- Building RESTful Web Services with .NET Core
- 物聯網