javascript - how does this callback function work -
i new nodejs , n00b of javascript. saw code create server using nodejs. can understand anonymous function called after request reached server.
var http=require("http"); http.createserver(function(request,response){ response.writehead(200,{"content-type":"text/plain"}); response.write("hello world"); responde.end(); }).listen(8888); my question how implement similar createserver function (foo() bar())..in order understand how method works.
in order make clear. have done not working. , how make work createserver() ?
function dummycallback(para1,para2,callback) { console.log('para1 ' + para1+' para2 '+ para2); callback(); } dummycallback(1,2,function(req,res) { req.senddata("good"); }); i have seen these code everywhere in nodejs desperately want know details...thanks again
maybe, asking how anonymous function works.
var fun = function(foo){ if (foo) foo(1, 2); ///< if function foo exists, call it. } fun(function(p1, p2){ return p1 + p2; });
Comments
Post a Comment