Last active
June 14, 2022 13:15
-
-
Save pointofpresence/54e7625f7b5ef3469f7d59a917a167f0 to your computer and use it in GitHub Desktop.
TypeScript: Constructor arguments to class properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Старый подход... | |
| class Person { | |
| private first_name: string; | |
| private last_name: string; | |
| private age: number; | |
| private is_married: boolean; | |
| constructor(fname:string, lname:string, age:number, married:boolean) { | |
| this.first_name = fname; | |
| this.last_name = lname; | |
| this.age = age; | |
| this.is_married = married; | |
| } | |
| } | |
| //Новый подход, позволяющий сократить код... | |
| class Person { | |
| constructor( private first_name: string, | |
| private last_name: string, | |
| private age: number, | |
| private is_married: boolean){} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment