Book Image

TypeScript Essentials

By : Christopher Nance
Book Image

TypeScript Essentials

By: Christopher Nance

Overview of this book

Table of Contents (15 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...