程序员人生 网站导航

判断一个对象是否为Buffer对象

栏目:htmlcss时间:2016-07-01 08:12:07

1、问题背景

     不同数据类型对象变量,如何判断1个对象是不是为Buffer对象


2、实现源码

> you='anikdjfijkfjkdsjfkdjfkdjfkdjfkdjfkd'; 'anikdjfijkfjkdsjfkdjfkdjfkdjfkdjfkd' > hai=Buffer(128); <Buffer 90 a4 3d 00 00 00 00 00 c0 c5 3b 00 00 00 00 00 e0 93 3c 00 00 00 00 00 0a 00 00 00 00 00 00 00 08 94 3c 00 00 00 00 00 05 00 00 00 01 00 00 00 00 00 .. . > > typeof(you); 'string' > typeof(hai); 'object' > Buffer.isBuffer(you); false > Buffer.isBuffer(hai); true >

3、问题说明

(1)you是1个字符串,利用isBuffer()方法判断为false;

(2)hai是1个Buffer对象,利用isBuffer()方法判断为true

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐