当前位置:Gxlcms > JavaScript > Node.js函数

Node.js函数

时间:2021-07-01 10:21:17 帮助过:36人阅读

Node.js 函数

匿名函数:scope.js

[code]function execute(someFn, value) {
    someFn(value);
}
execute(function (word) {
    console.log(word)
}, 'hello');

275.png


函数传递是如何让HTTP服务工作的

案例:server.js

[code]var http = require('http');
var onRequest = function (request, response) {
    response.writeHead(200, { "Content-Type" : "text/plain"});
    response.write("Hello world");
    response.end();
}
http.createServer(onRequest).listen(8888);
console.log('服务器监听端口 8888');

276.png

客户端:http://localhost:8888/%E5%87%BD%E6%95%B0/server.js

277.png

以上就是Node.js 函数的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!

人气教程排行