The JavaScript language's object-oriented capabilities are built around the concept of prototypes. The prototype model defines links between objects, instead of inheritance trees. The prototype model, as powerful as it is, is not very friendly to the average JavaScript programmer. TypeScript enables us to create classes with a familiar syntax, and it's completely identical to JavaScript 1.5 classes (if we choose not to use TypeScript exclusive features). To define a class in TypeScript, we use the class
keyword:
class Product {}
Classes in TypeScript might have a constructor and methods just like JavaScript 2015. TypeScript also adds the ability to define class properties. The following example shows our Product
class with a constructor, property, and a method:
class Product { color; price; constructor(color, price) { this.color = color; this.price = price; } getProductDetails() { return this.color + this.price; } }
In TypeScript, just like JavaScript 2015...