December 2017
Beginner
372 pages
10h 32m
English
In the preceding example, we saw how we can initialize properties at the time of object creation using the constructor. We pass the parameter to the class, and, then, inside the constructor, we assign these parameters to the properties of the class. Parameter properties allow a short form to define these properties in a class.
In the following example, we have a class with three properties, namely, title, author, and length. The constructor takes three parameters which are then assigned to the property:
class Book { public author: string; public title: string; public length: number; constructor(author:string, title:string, length: number){ this.author = author; this.title = title; this.length = length; }}
We can accomplish ...
Read now
Unlock full access