11. Node. js function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.