Book Image

Typescript essentials

By : Christopher Nance
Book Image

Typescript essentials

By: Christopher Nance

Overview of this book

The book introduces the TypeScript language and its features to anyone looking to develop rich web applications. Whether you are new to web development or are an experienced engineer with strong JavaScript skills, this book will get you writing code quickly. A basic understanding of JavaScript and its language features are necessary for this book.
Table of Contents (10 chapters)

The basics


Before we dig into the main concepts of OOP, let's talk about what objects are and how they work. Objects are self-contained entities that maintain a set of data members and methods. The data members are unique to each object instance and the methods have direct access to these members. An object represents an instance of a class type and any number of instances can be created. Each of these instances will have different memory locations to store their internal member variables at runtime to differentiate between them. The following code sample shows a class definition and then the creation of different objects of that type:

class Shape {
    public locationX: number = 0;
    public locationY: number = 0;
    public height: number = 0;
    public width: number = 0;
    constructor() {
    }
    public draw() {
    }
    public resize(height: number, width: number) {
        this.height = height;
        this.width = width;
    }
    public move(x: number, y: number) {
        this...