3434 *
3535 * */
3636
37- function Ctx ( ) {
38- return { req : {
37+ const next = function ( ) {
38+ console . log ( "I'm NEXT" ) ;
39+ }
40+
41+ function Http ( ) { }
42+
43+ Http . prototype . createServer = function ( fn ) {
44+ const ctx = { req : {
3945 PORT : 123 ,
4046 url : 'google' ,
4147 } ,
@@ -47,31 +53,24 @@ function Ctx() {
4753 }
4854 }
4955 }
50- }
51-
52- const ctx = new Ctx ( ) ;
53-
54- const next = function ( ) {
55- console . log ( "I'm NEXT" ) ;
56- }
57-
58- function Http ( ) { }
59- Http . prototype . createServer = function ( fn ) {
60- this . temp = fn ;
56+
57+
58+ this . callback = ( ) => {
59+ return fn ( ctx , next ( ) )
60+ }
6161 return this ;
6262}
6363
6464Http . prototype . listen = function ( PORT , host ) {
6565 console . log ( `https://${ host } :${ PORT } ` ) ;
66- this . temp ( ctx , next ) ;
67- this . temp = null ;
66+ this . callback ( ) ;
67+ this . callback = null ;
6868
6969 return this ;
7070}
7171
7272const server = new Http ( ) . createServer ( function ( ctx , next ) {
7373 console . log ( ctx ) ;
74- next ( ) ;
7574} ) . listen ( 3000 , 'localhost' ) ;
7675
7776
@@ -91,36 +90,34 @@ function Human(object) {
9190 this . gender = object . gender ;
9291 this . height = object . height ;
9392 this . weigth = object . weigth ;
94- this . inheritHuman = function ( ) {
95- return this ;
96- }
9793}
9894
99- Human . prototype . Worker = function ( object ) {
95+ function Worker ( object ) {
10096 this . company = object . company ;
10197 this . salary = object . salary ;
10298 this . toWork = function ( ) {
10399 return 'work' ;
104100 }
105- this . inheritProperties = this . inheritHuman ( ) ;
101+ Human . call ( this , object )
102+ Worker . prototype = new Human ( object ) ;
106103}
107104
108- Human . prototype . Student = function ( object ) {
105+
106+ function Student ( object ) {
109107 this . university = object . university ;
110108 this . grants = object . grants ;
111109 this . toWatchSeries = function ( ) {
112110 return `watch tv series` ;
113111 }
114- this . inheritProperties = this . inheritHuman ( ) ;
112+ Human . call ( this , object )
113+ Student . prototype = new Human ( object ) ;
115114}
116115
117- const vasya = new Human ( { name : 'Vasya' , age : '30' , gender : 'Male' , height : '1.8 m' , weigth : '80 kg' } ) ;
118- vasya . Worker ( { company : 'qwerty' , salary : '007' } ) ;
116+ let vasya = new Worker ( { name : 'Vasya' , age : '30' , gender : 'Male' , height : '1.8 m' , weigth : '80 kg' , company : 'qwerty' , salary : '007' } ) ;
119117console . log ( vasya ) ;
120118console . log ( vasya . toWork ( ) ) ;
121119
122- const sasha = new Human ( { name : 'Sasha' , age : '18' , gender : 'Male' , height : '1.8 m' , weigth : '70 kg' } ) ;
123- sasha . Student ( { university : 'ytrewq' , grants : '700' } ) ;
120+ let sasha = new Student ( { name : 'Sasha' , age : '18' , gender : 'Male' , height : '1.8 m' , weigth : '70 kg' , university : 'ytrewq' , grants : '700' } ) ;
124121console . log ( sasha ) ;
125122console . log ( sasha . toWatchSeries ( ) ) ;
126123
@@ -136,12 +133,15 @@ console.log(sasha.toWatchSeries());
136133*/
137134
138135function wraper ( func ) {
139- wraper . prototype . args = 22 ;
140- return wraper . args ;
136+ return ( ...args ) => {
137+ console . log ( args ) ;
138+ return func ( ...args ) ;
139+ }
141140}
142141
143142function sum ( a , b ) {
144143 return a + b ;
145144}
146145
147- console . log ( wraper ( sum ( 2 , 2 ) ) )
146+ const test = wraper ( sum ) ;
147+ console . log ( test ( 10 , 12 ) )
0 commit comments