|
| 1 | +//Task1 |
| 2 | +let ctx = { |
| 3 | + req: { |
| 4 | + PORT: 'number', |
| 5 | + url: 'string' |
| 6 | + }, |
| 7 | + res: { |
| 8 | + status: 'number', |
| 9 | + message: 'string', |
| 10 | + header: { |
| 11 | + content_type: 'application/json' |
| 12 | + } |
| 13 | + } |
| 14 | +}; |
| 15 | + |
| 16 | +let next = function() { |
| 17 | + |
| 18 | +}; |
| 19 | + |
| 20 | +function Http() { |
| 21 | + |
| 22 | +}; |
| 23 | + |
| 24 | +Http.prototype.createServer = function(fn) { |
| 25 | + this.createServerCallback = fn; |
| 26 | + return this; |
| 27 | +}; |
| 28 | + |
| 29 | +Http.prototype.listen = function(PORT, host) { |
| 30 | + console.log(`Server running on https://${host}:${PORT}`); |
| 31 | + this.createServerCallback(ctx, next); |
| 32 | +}; |
| 33 | + |
| 34 | +const server = new Http().createServer(function(ctx, next) { |
| 35 | + console.log(ctx); |
| 36 | +}).listen(3000, 'localhost'); |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +//Task2 |
| 42 | +function Human (name, age, floor, growth, weight) { |
| 43 | + this.name = name, |
| 44 | + this.age = age, |
| 45 | + this.floor = floor, |
| 46 | + this.growth = growth, |
| 47 | + this.weight = weight |
| 48 | +}; |
| 49 | + |
| 50 | +function Worker (name, age, floor, growth, weight, placeOfWork, salary) { |
| 51 | + Human.apply(this, arguments); |
| 52 | + this.placeOfWork = placeOfWork, |
| 53 | + this.salary = salary, |
| 54 | + this.methodWorker = function () { |
| 55 | + console.log('Work!'); |
| 56 | + } |
| 57 | +}; |
| 58 | + |
| 59 | +function Student (name, age, floor, growth, weight, placesOfStudy, scholarship) { |
| 60 | + Human.apply(this, arguments); |
| 61 | + this.placesOfStudy = placesOfStudy, |
| 62 | + this.scholarship = scholarship, |
| 63 | + this.methodStudent = function () { |
| 64 | + console.log('watch TV shows'); |
| 65 | + } |
| 66 | +}; |
| 67 | + |
| 68 | +Worker.prototype = Object.create(Human.prototype); |
| 69 | + |
| 70 | +let worker1 = new Worker('Natalia', 24, 'woman', 168, 55, 'аптека', 7000); |
| 71 | +console.log(worker1); |
| 72 | +worker1.methodWorker(); |
| 73 | +let worker2 = new Worker('Natalia2', 23, 'woman', 167, 54, 'аптека', 7500); |
| 74 | +console.log(worker2); |
| 75 | +console.log(worker2.name); |
| 76 | + |
| 77 | +Student.prototype = Object.create(Human.prototype); |
| 78 | + |
| 79 | +let student1 = new Student('Natalia', 24, 'woman', 168, 55, 'easyCode', 2000); |
| 80 | +console.log(student1); |
| 81 | +student1.methodStudent(); |
| 82 | +let student2 = new Student('Natalia2', 23, 'woman', 167, 54, 'easyCode', 2500); |
| 83 | +console.log(student2); |
0 commit comments