简体   繁体   中英

How to get the class name of an Object in Node JS

Question is very Simple. If you instance, for example, a Buffer you do:

b = new Buffer(0);

then you check the type:

typeof b;

The result is 'Object', but I want to know it is a Buffer.

If you made this in the node console you get it:

>b = new Buffer(1024);
>typeof b
'object'
> b
<Buffer ...>

So, some how the console knows that b is a Buffer.

In your case:

b = new Buffer(1024);
if (b instanceof Buffer) {
  ...

More generally, see this answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM