December 2017
Beginner
372 pages
10h 32m
English
Static properties are properties of the class itself and not of the class instances, like we saw in the preceding example of the Book class. The advantage of static properties is that they allow us to store data specific to the class and do not change with different instances of the class. In the following example, we have a Book class with a static property named publisher:
class Book { public author: string; public title: string; public length: number; static publisher: string = "Packt Pub"; constructor(author:string, title:string, length: number){ this.author = author; this.title = title; this.length = length;} getFullTitle(): string { return `${this.title} by ${this.author}`; }}let typeScript = new Book("Sachin Ohri" ...
Read now
Unlock full access