内容:普通函数,匿名函数,函数传递是如何让http服务器工作的
###普通函数
例子:
function say(word) { console.log(word); } function execute(somefunction, value) { somefunction(value); } execute(say, "hello"); ###匿名函数 function execute(somefunction, value) { somefunction(value); } execute(function(word){ console.log(word) }, "hello");
####################################################################################
函数传递是如何让http服务器工作的
带着这些知识,我们再来看看我们简约而不简单的http服务器:
var http = require("http"); http.createserver(function(request, response) { response.writehead(200, {"content-type": "text/plain"}); response.write("hello world"); response.end(); }).listen(8888);
现在它看上去应该清晰了很多:我们向 createserver 函数传递了一个匿名函数。
用这样的代码也可以达到同样的目的:
var http = require("http"); function onrequest(request, response) { response.writehead(200, {"content-type": "text/plain"}); response.write("hello world"); response.end(); } http.createserver(onrequest).listen(8888);
总结
以上所述是小编给大家介绍的node.js 函数,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
微信小程序wx.scanCode扫描条形码,偶尔出现条形码不正确导致查询失败
Android 入门第七讲01-数据存储(数据存储概述,文件存储(raw和asserts目录读写,data/data/包名目录读写,sdcard目录读写),SharedPreferences读写)
vue-axios系列:axios拦截器,配置请求头,配置请求参数
网友评论