一个函数可以作为另一个函数的参数
function fn1(fn,arg){
fn(arg);
}
function name(n){
console.log("i am "+n);
}
fn1(name,"cyy");

使用匿名函数
function fn1(fn,arg){
fn(arg);
}
fn1(function(n){
console.log("i am "+n);
},"cyy2");

HTTP服务器实例:
var http=require("http");
http.createServer(function(request,response){
response.writeHead(200,{"Content-Type":"text/plain"});
response.write("hello http~");
response.end();
}).listen(8888);


来源:https://www.cnblogs.com/chenyingying0/p/12456321.html