diff --git a/src/task_1/index.ts b/src/task_1/index.ts index 53a04d7..a8f8b78 100644 --- a/src/task_1/index.ts +++ b/src/task_1/index.ts @@ -26,3 +26,29 @@ class Calculator { return (this.a + this.b).toString(); } } + +class Decor extends Calculator +{ + protected calculators: Calculator; + constructor(a: number, b: number) + { + super(a, b) + this.calculators = new Calculator(a, b) + } +} + +class DecorateRu extends Decor +{ + public exec(): string + { + return 'Результат сложения ${this.a} + ${this.b} = ${this.calculators.exec()}' + } +} + +class DecorateEn extends Decor +{ + public exec(): string + { + return 'Result of the addition operation ${this.a} + ${this.b} = ${this.calculators.exec()}' + } +} \ No newline at end of file diff --git a/src/task_2/index.ts b/src/task_2/index.ts index 06535aa..010a14a 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -5,10 +5,28 @@ * Когда присваивается некорректный e-mail возбуждается ошибка. */ -class Example { - public email: string = ""; +function check_mail(target: Object, propertyKey: string): any{ + let email = ""; + let discriptor: PropertyDescriptor = { + get: function() + { + return email; + }, + set: function(newmail: string) + { + let mail_write = /[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z0-9]+/ + if (mail_write.test(newmail)) + { + email = newmail; + console.log('email valid') + + } + else + { + throw "Invalid email" + } + } + } + return discriptor; } -let exampleInstance = new Example(); -exampleInstance.email = "fkkldfjg"; // генерирует эксепшен -exampleInstance.email = "misha@mail.ru"; // выводит в консоль e-mail valid diff --git a/src/task_4/index.ts b/src/task_4/index.ts index dc0e179..b8c02cc 100644 --- a/src/task_4/index.ts +++ b/src/task_4/index.ts @@ -6,6 +6,6 @@ function getProperty(obj: T, key: K): T[K] { return obj[key]; } -const x = undefined; +const x = {m: 7}; -console.log(getProperty(x, "m")); \ No newline at end of file +console.log(getProperty(x, "m"));