|
| 1 | +//'use strict'; |
| 2 | + |
| 3 | +/* |
| 4 | + * TASK ! ! ! |
| 5 | + * Сделайте пожалуйста с теми навыками которые у вас есть ТЕЛЕФОННЫЙ СПРАВОЧНИК |
| 6 | + * |
| 7 | + * Task 0 |
| 8 | + * |
| 9 | + * Создайте функцию конструктор Http, которая будет иметь 2 метода |
| 10 | + * |
| 11 | + * createServer() - принимает один аргумент функцию с двумя параметрами ctx и next |
| 12 | + * ctx: Object { |
| 13 | + * req: Object |
| 14 | + * PORT: number |
| 15 | + * url: string |
| 16 | + * res: Object |
| 17 | + * status: number, |
| 18 | + * message: string, |
| 19 | + * header: Object { |
| 20 | + * content-type:application/json |
| 21 | + * } |
| 22 | + * } |
| 23 | + * next: Function |
| 24 | + * |
| 25 | + * |
| 26 | + * при вызове listen(PORT, host) - в консоле должна отобразится надпись |
| 27 | + * "Server running on https://host:port" |
| 28 | + * и вызваться переданная в createServer функция |
| 29 | + * |
| 30 | + * |
| 31 | + * методы нужно вызывать через chain |
| 32 | + * после вызова метода listen() - должна вызываться переданная в createServer |
| 33 | + * первая функция и возвращать объект и функцию |
| 34 | + * |
| 35 | + * */ |
| 36 | + |
| 37 | +function Http() { |
| 38 | + this.ctx = { |
| 39 | + req :{ |
| 40 | + PORT: 8080, |
| 41 | + url: 'localhost' |
| 42 | + }, |
| 43 | + res: { |
| 44 | + status: 0, |
| 45 | + message: 'Server status', |
| 46 | + header: { |
| 47 | + type: 'application/json' |
| 48 | + } |
| 49 | + } |
| 50 | + }; |
| 51 | + this.next = function () { |
| 52 | + console.log(`${this.ctx.res.message} is ${this.ctx.res.status}`); |
| 53 | + } |
| 54 | +} |
| 55 | +Http.prototype.createServer = function(fn) { |
| 56 | + this.fn = function(){ |
| 57 | + return fn(this.ctx, this.next()); |
| 58 | + } |
| 59 | + return this |
| 60 | +} |
| 61 | + |
| 62 | +Http.prototype.listen = function(PORT, host) { |
| 63 | + console.log(`Server running on http://${host}:${PORT}`); |
| 64 | + this.fn(); |
| 65 | + return this |
| 66 | +} |
| 67 | + |
| 68 | +const server = new Http().createServer(function(ctx, next) { |
| 69 | + console.log(ctx); |
| 70 | +}).listen(3000, 'localhost'); |
| 71 | + |
| 72 | + |
| 73 | +// TASK 1 |
| 74 | +// Создать класс Human, у которого будут свойства обычного человека: |
| 75 | +// имя, возраст, пол, рост, вес. |
| 76 | +// Используя прототипное наследование создать дочерние классы Worker |
| 77 | +// (дописать в них поля места работы, зарплата, метод "работать") |
| 78 | +// и Student (дописать поля места учебы, стипендией, метод "смотреть сериалы") |
| 79 | +// |
| 80 | +// Создать несколько экземпляров классов Worker и Student, вывести их в консоль. |
| 81 | +// Убедиться что они имеют поля родительского класса Human |
| 82 | + |
| 83 | + function Human(name, age){ |
| 84 | + this.name = name; |
| 85 | + this.age = age; |
| 86 | + } |
| 87 | + |
| 88 | + function Worker(name, age, job, salary){ |
| 89 | + Human.apply(this, arguments); |
| 90 | + this.job = job; |
| 91 | + this.salary = salary; |
| 92 | + } |
| 93 | + |
| 94 | + Worker.prototype = Object.create(Human.prototype) |
| 95 | + |
| 96 | + Worker.prototype.work = function(){ |
| 97 | + console.log('i work!') |
| 98 | + } |
| 99 | + |
| 100 | + function Student(name, age, grand, studyPlase){ |
| 101 | + Human.apply(this, arguments) |
| 102 | + this.grand = grand; |
| 103 | + this.studyPlase = studyPlase |
| 104 | + } |
| 105 | + |
| 106 | + Student.prototype = Object.create(Human.prototype) |
| 107 | + |
| 108 | + Student.prototype.watchShow = function (){ |
| 109 | + console.log('i love watch TV show') |
| 110 | + } |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + let student1 = new Student('alex', 21, 300, 'universitet') |
| 115 | + let worker1 = new Worker('John', 43,'factory', 500) |
| 116 | + |
| 117 | + worker1.work() |
| 118 | + student1.watchShow(); |
| 119 | + console.log(student1) |
| 120 | + console.log(worker1) |
| 121 | + |
| 122 | +// @SUPER |
| 123 | + |
| 124 | +/* |
| 125 | + * |
| 126 | + * TASK 0 |
| 127 | + * Создайте функцию обертку над другой функцией |
| 128 | + * Каждый раз при вызове внутренней функции в консоле будут отображаться аргументы функции |
| 129 | + * которую мы обернули |
| 130 | + * |
| 131 | +*/ |
| 132 | + |
0 commit comments