簡體   English   中英

node.js中“ [,params_name]”的含義是什么?

[英]what's the meaning of '[,params_name]' in node.js?

這是關於response.writeHead(statusCode [,statusMessage] [,headers])的 node.js文檔。

我不了解“ statusCode [,statusMessage] [,標題]”,

它代表一個或多個參數嗎?

  • 如果是,為什么writeHead(200,后跟逗號?

    如果是兩個,為什么statusCode[, statusMessage][, headers]沒有逗號?

我可以在哪里傳遞json?

是否有任何有關這些參數規則的文件顯示?

例:

const body = 'hello world';
response.writeHead(200, {
  'Content-Length': Buffer.byteLength(body),
  'Content-Type': 'text/plain' });

規則很簡單-任何文字的方括號都表示“此文字是可選的”。 所以

response.writeHead(statusCode[, statusMessage][, headers])

表示以下所有

response.writeHead(statusCode, statusMessage, headers)
response.writeHead(statusCode, statusMessage)
response.writeHead(statusCode, headers)
response.writeHead(statusCode)

如果方括號嵌套為

response.writeHead(statusCode[, statusMessage[, headers]])

這意味着所有:

response.writeHead(statusCode, statusMessage, headers)
response.writeHead(statusCode, statusMessage)
response.writeHead(statusCode)

請注意,移除外部套件也會導致內部套件被移除

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM