diff --git a/src/task_1/index.ts b/src/task_1/index.ts index 53a04d7..2aa4549 100644 --- a/src/task_1/index.ts +++ b/src/task_1/index.ts @@ -26,3 +26,24 @@ class Calculator { return (this.a + this.b).toString(); } } + +class BaseDecorator extends Calculator { + protected wrappee: Calculator; + + constructor(a: number, b: number) { + super(a, b); + this.wrappee = new Calculator(a, b); + } +} + +class DecorateRu extends BaseDecorator{ + public exec(): string { + return `результат сложения ${this.a} + ${this.b} = ${this.wrappee.exec()}`; + } +} + +class DecorateEn extends BaseDecorator{ + public exec(): string { + return `result of the addition operation ${this.a} + ${this.b} = ${this.wrappee.exec()}`; + } +} \ No newline at end of file diff --git a/src/task_2/index.ts b/src/task_2/index.ts index 06535aa..6628713 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -12,3 +12,21 @@ class Example { let exampleInstance = new Example(); exampleInstance.email = "fkkldfjg"; // генерирует эксепшен exampleInstance.email = "misha@mail.ru"; // выводит в консоль e-mail valid + +function validateMail(target: Object, propertyKey: string | symbol): any { + let email = "" + let descriptor: PropertyDescriptor = { + get() { + return email + }, + set(newEmail: string) { + if (newEmail !== "" && !/[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z0-9]+/.test(newEmail)) { + throw 'Invalid email.' + } + console.log('email valid'); + email = newEmail; + } + } + + return descriptor; +} diff --git a/src/task_4/index.ts b/src/task_4/index.ts index dc0e179..f750ef8 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': 14}; console.log(getProperty(x, "m")); \ No newline at end of file