Skip to content

Commit

Permalink
My question file ^^
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Borboën committed Sep 12, 2014
1 parent 99d9fe6 commit a989c1b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions questions/how_function_are_called.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Simple test about function call
*/

var http = require('http');
function my_test (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});

// Call function 1
function_1(res);

// call function 2
function_2(res);

res.write('<br><br> Why are my functions called twice in console.log and only once in the browser ?');
res.end();
}


http.createServer(my_test).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

function function_1(res) {
res.write('<br> -> function_1 called');
console.log(' -> function_1 called');
return true;
}

function function_2(res) {
res.write('<br> -> function_2 called');
console.log(' -> function_2 called');
return true;
}

0 comments on commit a989c1b

Please sign in to comment.