js中typeof只能判断基础类型。

var a = null;

var b;

var c = function () { }

var d = [];

console.log(typeof a);//object 

console.log(typeof a);//object 

console.log(typeof c);//function

console.log(typeof d);//object

//这时候我们会发现d是一个数组,但是类型却是object。

--------------------------------------------------------------------------------------

所以这里建议大家用:

toString.call()来实现复合类型的数据类型判断。


猜你喜欢

转载自blog.csdn.net/bule_chen/article/details/51324686