I am implementing a http server for some project.
I have an HttpServer object that I created that contains in it a server (net module)
this server contains allot of info, and i want to pass it as parameter to the callback functions. like you would do with "setTimeout"
var time=setTimeout(function(**a**){do somthing}, 2000, **someObject**);
I tried doing something like that in my code but it does not recognize the parameter I passed as an object
var net = require('net');
function HttpServer(port){
this.port=port;
}
HttpServer.prototype.start = function (){
console.log("starting the server");
this.server = net.createServer(function (socket,server) {
console.log("my port is: "+server.port)
socket.on('data',function(dat){ });
},this);
//i am trying to send to the createserver callback function
//the parameter 'this' that actually is an HttpServer
//and the callback function secives it as 'server'
//when i run the program i get an error that server is
//undefiend and therefor does not have a member port
this.server.listen(this.port);
}
var httpserver= new HttpServer(4444);
httpserver.start();
Why it does not recognize the parameter sent?
bind. You can also achieve similar results with traditional utilisation of the statical scoping of the language.