【问题标题】:How to check if an object is of type IncomingMessage (NodeJS)如何检查对象是否属于 IncomingMessage (NodeJS) 类型
【发布时间】:2020-04-09 20:17:25
【问题描述】:

我不知道如何导入 NodeJS 类以检查对象。

基本上我想这样做:

if (context.req instanceof IncomingMessage)

https://nodejs.org/api/http.html#http_class_http_incomingmessage

【问题讨论】:

    标签: javascript node.js instanceof


    【解决方案1】:

    导入/要求http 模块:

    const http = require('http')
    
    //
    
    if (context.req instanceof http.IncomingMessage) {
        //
    }
    

    【讨论】:

    • 谢谢,我使用了import * as http from 'http';,但我想这也可以
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2018-07-10
    • 2011-01-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2022-01-25
    相关资源
    最近更新 更多