Compare commits
2 Commits
Lesson_Beg
...
master
Author | SHA1 | Date |
---|---|---|
|
f2cb6cf6dd | |
|
25a4e7d988 |
25
src/index.ts
25
src/index.ts
|
@ -1,3 +1,7 @@
|
||||||
|
|
||||||
|
// ########################## УЧЕБНЫЙ ТЕКСТ ############################################################
|
||||||
|
//******************************************************************************************************
|
||||||
|
|
||||||
interface People {
|
interface People {
|
||||||
name: string;
|
name: string;
|
||||||
age: number | undefined;
|
age: number | undefined;
|
||||||
|
@ -40,6 +44,12 @@ class ProcessingPeoples implements PeopleLocation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let str: string = 'test text';
|
||||||
|
let proc1 = new ProcessingPeoples(str)
|
||||||
|
console.log(proc1)
|
||||||
|
proc1.name = 'new test'
|
||||||
|
console.log(proc1)
|
||||||
|
|
||||||
class ProcessingPeoplesExt extends ProcessingPeoples {
|
class ProcessingPeoplesExt extends ProcessingPeoples {
|
||||||
isActive: boolean = false;
|
isActive: boolean = false;
|
||||||
|
|
||||||
|
@ -64,13 +74,16 @@ class Duck {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let Utka: Duck = new Duck();
|
||||||
|
Utka.log();
|
||||||
|
|
||||||
interface Eateable {
|
interface Eateable {
|
||||||
eat(): void;
|
eat(): void; //пустота, функция ничего не принимает и не возвращает.
|
||||||
}
|
}
|
||||||
|
|
||||||
class GreyDuck extends Duck implements Eateable{
|
class GreyDuck extends Duck implements Eateable{ //наследоваться можно от другого класса только один раз, но!! реализация интерфейсов может быть не ограниченно количество раз
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super(); // в данном примере, если используется конструктор и при этом этот конструктор наслеедуется от родителя, то мы обязаны вызывать конструктор родителя.
|
||||||
this.type = 'GreyDuck'
|
this.type = 'GreyDuck'
|
||||||
}
|
}
|
||||||
override log(){
|
override log(){
|
||||||
|
@ -86,6 +99,7 @@ class RedDuck extends Duck implements Eateable {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.type = 'RedDuck'
|
this.type = 'RedDuck'
|
||||||
|
console.log(`Object created ${this.type}`)
|
||||||
}
|
}
|
||||||
eat(): void {
|
eat(): void {
|
||||||
console.log("I'm eat");
|
console.log("I'm eat");
|
||||||
|
@ -103,6 +117,9 @@ let array: Eateable[] = [
|
||||||
duck2
|
duck2
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let result = array[0]; //мы можем проверить содержание массива с именем array. в квадратных скобках мы указали ноль = это первый эелемент массива.
|
||||||
|
console.log(`результат содержимого массива${JSON.stringify(result)}`); //вывод на экран
|
||||||
|
|
||||||
for (let item of array) {
|
for (let item of array) {
|
||||||
item.eat();
|
item.eat();
|
||||||
}
|
}
|
||||||
|
@ -116,5 +133,5 @@ for (let item of array2) {
|
||||||
item.log();
|
item.log();
|
||||||
}
|
}
|
||||||
|
|
||||||
array2.filter(item => "eat" in item);
|
array2.filter(item => "eat" in item); //тестирование не относится к тексту выше
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue