-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
144 lines (113 loc) · 3.89 KB
/
Copy pathjs.js
File metadata and controls
144 lines (113 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// 'use strict';
/*
* TASK ! ! !
* Сделайте пожалуйста с теми навыками которые у вас есть ТЕЛЕФОННЫЙ СПРАВОЧНИК
*
* Task 0 !!!! Didn't done!!!
*
* Создайте функцию конструктор Http, которая будет иметь 2 метода
*
* createServer() - принимает один аргумент функцию с двумя параметрами ctx и next
* ctx: Object {
* req: Object
* PORT: number
* url: string
* res: Object
* status: number,
* message: string,
* header: Object {
* content-type:application/json
* }
* }
* next: Function
*
*
* при вызове listen(PORT, host) - в консоле должна отобразится надпись
* "Server running on https://host:port"
* и вызваться переданная в createServer функция
*
*
* методы нужно вызывать через chain
* после вызова метода listen() - должна вызываться переданная в createServer
* первая функция и возвращать объект и функцию
*
* */
function Http() {};
Http.prototype.createServer = function(fn) {
let stx = {
req: {
port: 123,
url: `http`,
},
res: {
status: 0,
message: `ok`,
haeder: {
'content-type': `application/json`,
}
}
}
this.callback = () => {
fn(ctx , ()=>{})
}
return this;
}
Http.prototype.listen = function(PORT, host) {
console.log(`Server running on https://${host}:${PORT}`);
};
const server = new Http().createServer(function(ctx, next) {
console.log(ctx);
}).listen(3000, 'localhost');
// server.createServer(function(ctx, next) {
// console.log(ctx);
// })
// console.log(server);
// TASK 1
// Создать класс Human, у которого будут свойства обычного человека:
// имя, возраст, пол, рост, вес.
// Используя прототипное наследование создать дочерние классы Worker
// (дописать в них поля места работы, зарплата, метод "работать")
// и Student (дописать поля места учебы, стипендией, метод "смотреть сериалы")
//
// Создать несколько экземпляров классов Worker и Student, вывести их в консоль.
// Убедиться что они имеют поля родительского класса Human
function Human(name,age,sex,hight,weight) {
this.name = name;
this.age = age;
this.sex = sex;
this.hight = hight;
this.weight = weight;
}
function Worker(sallary, keyshiya) {
this.sallary = sallary;
this.workPlace = keyshiya;
}
function Student(university, scholarship) {
this.university = university;
this.scholarship = scholarship;
}
Worker.prototype = Object.create(Human.prototype);
Worker.prototype.constructor = Worker;
Worker.prototype.arbeiten = function() {
console.log(`arbeite macht frie`);
}
Student.prototype = Object.create(Human.prototype);
Student.prototype.constructor = Student;
Student.prototype.lookingOfTVSeries = function() {
console.log(`Say: Lannisters always pay their debts`);
}
let studentExemplar1 = new Student(`HPI`,`-1200`);
let workerExemplar1 = new Worker(`400$`,`somewhere`);
let humanExample1 = new Human(`Vasia`,`18`,`man`,`165`,`55`);
console.log(studentExemplar1);
console.log(workerExemplar1);
console.log(humanExample1);
// @SUPER
/*
*
* TASK 0
* Создайте функцию обертку над другой функцией
* Каждый раз при вызове внутренней функции в консоле будут отображаться аргументы функции
* которую мы обернули
*
*/