请参阅 Nodejs 文档中的示例
response.writeHead(statusCode[, statusMessage][, headers])
const body = 'hello world';
response
.writeHead(200, {
'Content-Length': Buffer.byteLength(body),
'Content-Type': 'text/plain',
})
.end(body);
writeHead 函数的第二个参数应该是“statusMessage”。 为什么第二个参数可以自动跳过,不需要参数未定义或为空? Nodejs 如何知道第三个参数的对象。
为什么不
const body = 'hello world';
response
.writeHead(200, undefined, {
'Content-Length': Buffer.byteLength(body),
'Content-Type': 'text/plain',
})
.end(body);
Nodejs 如何知道第三个参数的对象。