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] Classes in TypeScript are very similar…to classes in C#.…There are a few things to know, however.…First, classes, properties, and fields…are all public by default.…You must refer to your properties and fields…with the "this" keyword,…even when the situation is unambiguous.…Constructors work, as you would expect,…except, and this is very cool,…you can automatically turn your constructor parameters…into properties or fields…by using the keyword public for properties,…and private for fields.…
We'll see that next, but first,…let's take a look at this demo.…We're going to begin by creating a new file…and we'll call that new file classes.ts.…In that new file, let's create a class.…We'll call that class Person.…Inside the Person class, we're going to create…a series of properties and fields,…much as we might do in C#.…We'll have a firstName property of type string.…
Now, notice that this property…has an initial lower case letter,…and that's the convention for properties.…You can tell that it's a property…because of the keyword public.…
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: Classes