Class & Object in TypeScript Part-6

In our previous post we have overview about function Overloading in Type Script.Today we will learn about Class & object

Class:

A class is a Template which contains attributes and methods.It is one kind of costume data type.
Class is used to create unlimited Objects.

ClassStructure

Fig: Class structure

There are three sections in above fig.
Class Name:
You have to give name of class.Ex- Employee.
Attributes:
You have to define class’s attributes . let class name Employee . you have to brainstorming, what will be attributes? Ex-1. FirstName. 2. LastName.
Method:
You have to define what kind of task will you do using this class. Ex-1. GetFullName() 2. GetReverseName()
Object:
Object is an individual instance which create from specific class.

Object

Fig: Multiple object from class

We can see above picture. One Employee class and four objects of employee class.Object may be created unlimited that mean  when you need to create object then you can create object

Let’s go to code.

Let’s get explain about code:

Class Name Employee

Both lines are class attributes.

There are two method in above code one is GetFullName() and other one is Ger ReverseName().

Object has created which name is aemployee.

Class’s attributes have assigned which are FirstName and LastName

Two Methods have called and kept in variable

Those are simple javascript code,get html tag and assign value.

Hope this will be helpful 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *