Last Sync: 2022-09-20 13:30:05
This commit is contained in:
parent
399b057328
commit
27e23cdd56
1 changed files with 7 additions and 4 deletions
|
@ -2,8 +2,7 @@
|
||||||
categories:
|
categories:
|
||||||
- Programming Languages
|
- Programming Languages
|
||||||
|
|
||||||
tags:
|
tags: [typescript, OOP]
|
||||||
- typescript
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# Classes
|
# Classes
|
||||||
|
@ -65,7 +64,7 @@ The main points to note are:
|
||||||
In order to create an object instance of `Age`, we can use the standard constructor function, viz:
|
In order to create an object instance of `Age`, we can use the standard constructor function, viz:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const mum = new Age('Mary Jo', 1959);
|
const mum = new Age("Mary Jo", 1959);
|
||||||
console.log(mum);
|
console.log(mum);
|
||||||
|
|
||||||
/* Age { personName: 'Mary Jo', birthYear: 1959 } */
|
/* Age { personName: 'Mary Jo', birthYear: 1959 } */
|
||||||
|
@ -74,7 +73,7 @@ console.log(mum);
|
||||||
But given that classes define objects, we can also now use `Age` as a new custom type and define an object that way
|
But given that classes define objects, we can also now use `Age` as a new custom type and define an object that way
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
const thomas: Age = new Age('Thomas', 1988);
|
const thomas: Age = new Age("Thomas", 1988);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Without constructor
|
### Without constructor
|
||||||
|
@ -118,3 +117,7 @@ class Programmer implements Person {
|
||||||
employed: () => boolean
|
employed: () => boolean
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Inheritance
|
||||||
|
|
||||||
|
### `implements` vs `extends`
|
||||||
|
|
Loading…
Add table
Reference in a new issue