Node.js 函数

送分小仙女□ 提交于 2020-03-10 16:36:58

一个函数可以作为另一个函数的参数

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);

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!