您的位置:首页 > Web前端 > Node.js

Node.js学习 - Function

2016-04-15 22:41 573 查看
Node.js函数和JavaScript类似

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服务器工作的

var http = require("http");

http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);

也可以这样:
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: