如何检查对象是否是Express.Router的实例?

时间:2017-12-19 10:14:57

标签: node.js express type-assertion

有谁能告诉我如何正确地做到这一点?

import {Router} from 'express';
import assert from 'assert'

let routerInstance = new Router();

assert(routerInstance instanceof Router); // this is throwing an error

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

With a little experiment, I did this instead:

Object.getPrototypeOf(routerInstance) == express.Router; //this returns true