filmov
tv
Typescript #15: Methods & Constructors in Typescript

Показать описание
So similar to the member variables in a class we can define member functions in the class as well. Lets see how can we do that . Lets say I want to create a method getstudentDetails which would return me the name of the student and the course he is enrolled for. Then I can declare that as we normally declare a function by function name getstudentdetails followed by function body.
Inside the function I will return the name and course property as return name of the student is enrolled for name of the course. Now we are returning name and course property of the class for the object which has called the method getstudentdetails as every object created will have details of a different student.
Inside the function I will return the name and course property as return name of the student is enrolled for name of the course. Now we are returning name and course property of the class for the object which has called the method getstudentdetails as every object created will have details of a different student.