Content: Normal functions, anonymous functions, how function delivery makes HTTP server work
###Normal Functions
example:
function say(word) { (word); } function execute(someFunction, value) { someFunction(value); } execute(say, "Hello"); ###Anonymous Functionsfunction execute(someFunction, value) { someFunction(value); } execute(function(word){ (word) }, "Hello");
####################################################################################
How does function pass make HTTP server work
With this knowledge, let’s take a look at our simple but not simple HTTP server:
var http = require("http"); (function(request, response) { (200, {"Content-Type": "text/plain"}); ("Hello World"); (); }).listen(8888);
Now it should look much clearer: we passed an anonymous function to the createServer function.
The same purpose can be achieved using such code:
var http = require("http"); function onRequest(request, response) { (200, {"Content-Type": "text/plain"}); ("Hello World"); (); } (onRequest).listen(8888);
Summarize
The above is the function introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time!