Skip to content

Commit ababc76

Browse files
Balashov NikitaOlegLustenko
authored andcommitted
homework-12
1 parent 3681fbb commit ababc76

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Home work 12</title>
6+
</head>
7+
<body>
8+
9+
<script src="src/main.js"></script>
10+
</body>
11+
</html>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
const ctx = {
38+
req: {
39+
PORT: 123,
40+
url: 'google',
41+
},
42+
res: {
43+
status: 1,
44+
message: 'HELLO',
45+
header: {
46+
contentType: 'application/json'
47+
}
48+
}
49+
}
50+
51+
const next = function() {
52+
console.log("I'm NEXT");
53+
}
54+
55+
function Http() { }
56+
Http.prototype.createServer = function(fn) {
57+
this.temp = fn;
58+
return this;
59+
}
60+
61+
Http.prototype.listen = function(PORT, host) {
62+
console.log(`https://${host}:${PORT}`);
63+
this.temp(ctx, next);
64+
this.temp = null;
65+
66+
return this;
67+
}
68+
69+
const server = new Http().createServer(function(ctx, next) {
70+
console.log(ctx);
71+
next();
72+
}).listen(3000, 'localhost');
73+
74+
75+
// TASK 1
76+
// Создать класс Human, у которого будут свойства обычного человека:
77+
// имя, возраст, пол, рост, вес.
78+
// Используя прототипное наследование создать дочерние классы Worker
79+
// (дописать в них поля места работы, зарплата, метод "работать")
80+
// и Student (дописать поля места учебы, стипендией, метод "смотреть сериалы")
81+
//
82+
// Создать несколько экземпляров классов Worker и Student, вывести их в консоль.
83+
// Убедиться что они имеют поля родительского класса Human
84+
85+
function Human(object) {
86+
this.name = object.name;
87+
this.age = object.age;
88+
this.gender = object.gender;
89+
this.height = object.height;
90+
this.weigth = object.weigth;
91+
}
92+
93+
function Worker(object) {
94+
this.company = object.company;
95+
this.salary = object.salary;
96+
this.toWork = function() {
97+
return 'work';
98+
}
99+
}
100+
101+
function Student(object) {
102+
this.university = object.university;
103+
this.grants = object.grants;
104+
this.toWatchSeries = function() {
105+
return`watch tv series`;
106+
}
107+
}
108+
109+
const vasya = new Human({name: 'Vasya', age: '30', gender: 'Male', height: '1.8 m', weigth: '80 kg'});
110+
vasya.__proto__ = new Worker({company: 'qwerty', salary: '007'});
111+
console.log(vasya);
112+
console.log(vasya.toWork());
113+
114+
const sasha = new Human({name: 'Sasha', age: '18', gender: 'Male', height: '1.8 m', weigth: '70 kg'});
115+
sasha.__proto__ = new Student({university: 'ytrewq', grants: '700'});
116+
console.log(sasha);
117+
console.log(sasha.toWatchSeries());
118+
119+
// @SUPER
120+
121+
/*
122+
*
123+
* TASK 0
124+
* Создайте функцию обертку над другой функцией
125+
* Каждый раз при вызове внутренней функции в консоле будут отображаться аргументы функции
126+
* которую мы обернули
127+
*
128+
*/
129+

0 commit comments

Comments
 (0)