When you chain a method in javascript, does it get called on the initial object? Or the return object of the previous method?
I am asking this because in Node I am chaining .listen().
It works:
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {
'Content-Type': 'text/plain'
});
response.end('Hello World\n');
}).listen(8088);
// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
It doesn't work when listen() is called after createServer:
http.createServer(function (request, response) {
response.writeHead(200, {
'Content-Type': 'text/plain'
});
response.end('Hello World\n');
})
http.listen(8088);
It says that listen() is not function. Why does it work when I chain it then?