From 022b9affb60e3b14328ce087b37d340e7ed975bf Mon Sep 17 00:00:00 2001 From: Foxovsky-bit Date: Thu, 15 Apr 2021 22:11:39 +0500 Subject: [PATCH 1/2] =?UTF-8?q?3=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task_1/index.ts | 16 ++++++++++++++++ src/task_2/index.ts | 12 ++++++++++++ src/task_4/index.ts | 4 +++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/task_1/index.ts b/src/task_1/index.ts index 53a04d7..afc1a77 100644 --- a/src/task_1/index.ts +++ b/src/task_1/index.ts @@ -8,6 +8,18 @@ * результат в виде строки на английском языке: * result of the addition operation ${a} + ${b} = ${рассчитанное значение} */ +function DecorateRu(target:any,method:string,descriptor:PropertyDescriptor) { + descriptor.value = function() { + return `результат сложения ${this.a} + ${this.b} = ${this.a + this.b}`; + } +} + +function DecorateEn(target:any,method:string,descriptor:PropertyDescriptor) { + descriptor.value = function() { + return `result of the addition operation ${this.a} + ${this.b} = ${this.a + this.b}`; + } +} + class Calculator { protected a: number = 0; @@ -22,7 +34,11 @@ class Calculator { } } + @DecorateEn public exec(): string { return (this.a + this.b).toString(); } } + +let calc = new Calculator(100,25); +console.log(calc.exec()); diff --git a/src/task_2/index.ts b/src/task_2/index.ts index 06535aa..0f876d9 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -4,8 +4,20 @@ * Когда присваивается корректный e-mail в консоль выводится сообщение email valid. * Когда присваивается некорректный e-mail возбуждается ошибка. */ +function valid(target: Object, propertyKey: string):any{ + let descriptor:PropertyDescriptor = { + set(email : string) { + if (email.match(/^([\w.*-]+@([\w-]+\.)+[\w-]{2,4})?$/g)){ + console.log("email valid"); + } + else throw "Invalid" + } + } + return descriptor; +} class Example { + @valid public email: string = ""; } diff --git a/src/task_4/index.ts b/src/task_4/index.ts index dc0e179..41e7e67 100644 --- a/src/task_4/index.ts +++ b/src/task_4/index.ts @@ -6,6 +6,8 @@ function getProperty(obj: T, key: K): T[K] { return obj[key]; } -const x = undefined; +const x = { + m:"prop" +}; console.log(getProperty(x, "m")); \ No newline at end of file From 57ba980b42f6a866194ad084443f0e8352262c0d Mon Sep 17 00:00:00 2001 From: Foxovsky-bit Date: Sat, 17 Apr 2021 16:37:38 +0500 Subject: [PATCH 2/2] task2 --- src/task_2/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/task_2/index.ts b/src/task_2/index.ts index 0f876d9..cceb16e 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -5,10 +5,15 @@ * Когда присваивается некорректный e-mail возбуждается ошибка. */ function valid(target: Object, propertyKey: string):any{ + let email = ""; let descriptor:PropertyDescriptor = { - set(email : string) { - if (email.match(/^([\w.*-]+@([\w-]+\.)+[\w-]{2,4})?$/g)){ + get() { + return email; + }, + set(setEmail : string) { + if (setEmail.match(/^([\w.*-]+@([\w-]+\.)+[\w-]{2,4})?$/g)){ console.log("email valid"); + email = setEmail; } else throw "Invalid" }