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..cceb16e 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -4,8 +4,25 @@ * Когда присваивается корректный e-mail в консоль выводится сообщение email valid. * Когда присваивается некорректный e-mail возбуждается ошибка. */ +function valid(target: Object, propertyKey: string):any{ + let email = ""; + let descriptor:PropertyDescriptor = { + get() { + return email; + }, + set(setEmail : string) { + if (setEmail.match(/^([\w.*-]+@([\w-]+\.)+[\w-]{2,4})?$/g)){ + console.log("email valid"); + email = setEmail; + } + 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