Content: Common functions, anonymous functions, how the function is passed to the HTTP server to work
# # #普通函数
Example:
function Say (Word) { console.log (word);} function Execute (someFunction, value) { "Hello");
# # #匿名函数
function Execute (someFunction, value) { someFunction (value);} Execute (function(word) {Console.log (Word)}, "Hello");
####################################################################################
function passing is how to get the HTTP server to work
With this knowledge, let's take a look at our simple and not simple HTTP server:
var http = require ("http"); Http.createserver (function(request, response) { Response.writehead ($, {"Content-type": "Text/plain"}); Response.Write ("Hello World"); Response.End ();}). Listen (8888);
Now it should look a lot clearer: we passed an anonymous function to the Createserver function.
This code can also be used to achieve the same purpose:
var http = require ("http"); function onrequest (Request, Response) { Response.writehead ($, {"Content-type": "Text/plain"}); Response.Write ("Hello World"); Response.End ();} Http.createserver (ONrequest). Listen (8888);
11. Node. js function