Classes

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, ...

Get Angular 2 Components now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.