Javascript-форум (https://javascript.ru/forum/)
-   Node.JS (https://javascript.ru/forum/node-js-io-js/)
-   -   ... is not a function (https://javascript.ru/forum/node-js-io-js/75495-not-function.html)

Роман Андреевич 15.10.2018 06:29

... is not a function
 
Коллеги, доброго времени суток, прошу помощи. Осваиваю nodejs и javascript и столкнулся с такой проблемой:

Главный файл:
// server.js
'use strict';

const Engine = require('./engine');
const engine = new Engine;

engine.startEngine();


далее engine.js:
// engine.js
'use strict';

const http = require('http');
const config = require('./config.json');
const Router = require('./router');

class Engine {

	constructor() {

		this.router = new Router();

	}

	createServer() {

		this.server = http.createServer(this.router.requestHandler);

		this.server.listen(config.main.port, config.main.host, () => {
   
			console.log(`Сервер запущен: порт(${config.main.port}), хост (${config.main.host})...`);
		 
		});

	}

	startEngine() {

		this.createServer();

	}

}

module.exports = Engine;


ну и собственно router, который выдает ошибку:
// router.js
'use strict';

const config = require('../config.json');
const url = require('url');
const fs = require('fs');

class Router {

	constructor() {

		
		
	}

	getRequest(req, res) {

		console.log(req.url);
		res.end();

	}

	requestHandler(req, res) {
		
	   if (req.method === 'GET') this.getRequest(req, res);

	}

}

module.exports = Router;


Так вот проблема, когда вызываю this.getRequest в консоль падает ошибка this.getRequest is not a function. Подскажите что не так????
Заранее благодарю

destus 15.10.2018 06:55

this.server = http.createServer(this.router.requestHandler.bind(this.router));

Роман Андреевич 15.10.2018 06:56

destus, а в чем проблема была??? Контекст потерялся???

destus 15.10.2018 07:01

Роман Андреевич,
да

Роман Андреевич 15.10.2018 07:03

destus, + 100500 к вашей карме))))) Спасибо


Часовой пояс GMT +3, время: 23:40.