Classes serve the same function as they do in C# except that they are public by default as are their members. TypeScript constructors are illustrated.
- [Instructor] We've already taken a look…at how to use classes in the more traditional way,…more like C#, where we created properties and fields…and then passed in parameters to the constructor…and assigned the parameters to the properties and fields.…TypeScript offers a different and more efficient way…to do this as well.…Let's create a file called classes2.ts,…and this time, we're going to create a new class,…let's call it Person2, and in Person2,…we're not going to declare any properties or fields.…
We're going to declare a constructor, as we did last time,…however, the parameters to that constructor…are going to be declared…with the keywords public and private.…We'll start by saying public firstName: string.…Now, this does two things.…It says that I have a parameter firstName,…which works exactly as any other parameter.…But it also declares an implicit property named firstName,…and I can do that again with lastName,…which will be a string.…
We'll make a third implicit property email,…which will be a string,…
Released
1/5/2017In this course, Jesse Liberty reviews the fundamentals of TypeScript for the C# developer, including the built-in types, flow controls, and functions. He covers default, optional, and rest parameters; lambda functions; object literals; and the creation and use of custom classes. Plus, learn about other object-oriented features such as inheritance and interfaces. By the end of the course, C# developers should be well on their way to incorporating this flexible and powerful web programming language into their app development workflow.
- Setting up a TypeScript development environment
- Working with types and variables
- Using operators to control flow
- Working with parameters and functions
- Creating classes and objects
- Exploring TypeScript inheritance
- Working with interfaces
Share this video
Embed this video
Video: Class constructor