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)

Encapsulation

The concept of encapsulation in OOP allows us to define all of the necessary members for an object to function while hiding the internal implementation details from the application using the object. This is a very powerful concept for us to use because it allows us to change the internal workings of a class without breaking any of its dependent objects. This could come in the form of either private members or private method implementations. The contract that has been established remains the same and the functionality that it provides is consistent, however, improvements are able to be made. In the following code segment, you can see how hiding certain members from the calling application will be beneficial:

interface IActivator {
    activateLicense(): boolean;
}
class LocalActivator implements IActivator {
    private _remainingLicenses: number = 5;
    constructor() {
    }
    public activateLicense(): boolean {
        this._remainingLicenses--;
        if (this._remainingLicenses...