forked from csxiaoyaojianxian/JavaScriptStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-函数.js
More file actions
29 lines (27 loc) · 771 Bytes
/
Copy path06-函数.js
File metadata and controls
29 lines (27 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 【函数作为参数】
function say(word) {
console.log(word);
}
function execute(someFunction, value) {
someFunction(value);
}
execute(say, "Hello");
// 【匿名函数】
function execute2(someFunction, value) {
someFunction(value);
}
execute2(function(word){ console.log(word) }, "Hello");
// 【以 http 为例】
// 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);
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);