From af65aab22757cc3321bed30f6bd007e0c68b4b3f Mon Sep 17 00:00:00 2001 From: George Tsendra Date: Tue, 10 Jul 2018 13:48:16 +0300 Subject: [PATCH 1/2] HM12 --- homework-12/index.html | 12 +++++ homework-12/js.js | 112 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 homework-12/index.html create mode 100644 homework-12/js.js diff --git a/homework-12/index.html b/homework-12/index.html new file mode 100644 index 0000000..04dc733 --- /dev/null +++ b/homework-12/index.html @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/homework-12/js.js b/homework-12/js.js new file mode 100644 index 0000000..e81f3c7 --- /dev/null +++ b/homework-12/js.js @@ -0,0 +1,112 @@ +// '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) { + console.log(fn); +} + +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; + this.arbeiten = function() { + console.log(`arbeite macht frie`); + }; +} +function Student(university, scholarship) { + this.university = university; + this.scholarship = scholarship; + this.lookingOfTVSeries = function() { + console.log(`Say: Lannisters always pay their debts`); + } +} +Worker.prototype = new Human(); +Student.prototype = new Human(); +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 + * Создайте функцию обертку над другой функцией + * Каждый раз при вызове внутренней функции в консоле будут отображаться аргументы функции + * которую мы обернули + * +*/ From e63d82e72969dd3495a5a8e3262a8bbf3f80f291 Mon Sep 17 00:00:00 2001 From: George Tsendra Date: Thu, 12 Jul 2018 13:19:09 +0300 Subject: [PATCH 2/2] hm12 try 2 --- homework-12/js.js | 54 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/homework-12/js.js b/homework-12/js.js index e81f3c7..65f3ee6 100644 --- a/homework-12/js.js +++ b/homework-12/js.js @@ -38,7 +38,26 @@ function Http() {}; Http.prototype.createServer = function(fn) { - console.log(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) { @@ -47,9 +66,9 @@ Http.prototype.listen = function(PORT, host) { }; -// const server = new Http().createServer(function(ctx, next) { -// console.log(ctx); -// }).listen(3000, 'localhost'); +const server = new Http().createServer(function(ctx, next) { + console.log(ctx); + }).listen(3000, 'localhost'); // server.createServer(function(ctx, next) { @@ -79,19 +98,32 @@ function Human(name,age,sex,hight,weight) { function Worker(sallary, keyshiya) { this.sallary = sallary; this.workPlace = keyshiya; - this.arbeiten = function() { - console.log(`arbeite macht frie`); - }; + } + + + function Student(university, scholarship) { this.university = university; this.scholarship = scholarship; - this.lookingOfTVSeries = function() { + +} + + + + +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`); - } } -Worker.prototype = new Human(); -Student.prototype = new Human(); + let studentExemplar1 = new Student(`HPI`,`-1200`); let workerExemplar1 = new Worker(`400$`,`somewhere`); let humanExample1 = new Human(`Vasia`,`18`,`man`,`165`,`55`);