99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

函數(shù)傳遞是如何讓HTTP服務(wù)器工作的

2018-02-24 15:25 更新

帶著這些知識(shí),我們?cè)賮?lái)看看我們簡(jiǎn)約而不簡(jiǎn)單的HTTP服務(wù)器:

var http = require("http");

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

現(xiàn)在它看上去應(yīng)該清晰了很多:我們向?createServer?函數(shù)傳遞了一個(gè)匿名函數(shù)。

用這樣的代碼也可以達(dá)到同樣的目的:

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

也許現(xiàn)在我們?cè)搯?wèn)這個(gè)問(wèn)題了:我們?yōu)槭裁匆眠@種方式呢?

以上內(nèi)容是否對(duì)您有幫助:
在線(xiàn)筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)