1.使用普通类型的typeof();
使用typeof只能判断出Object类型,toString会将内容有序打印出来,不能判断
2.使用toString();
toString会将内容有序打印出来,不能判断
3.使用(对象名).constructor.name
直接寻找对象的原型对象,然后找到对象的构造函数,再然后再取出其名字,准确
4.使用Object.prototype.toString.call(对象)
借调Object构造函数的原型链上面的方法,准确
判断内置对象Array的结果
var arr=new Array(3);
console.log(typeof(arr));
console.log(arr.toString());
console.log(arr.__proto__.constructor.name);
console.log(Object.prototype.toString.call(arr));
效果:
判断内置对象Date的结果
<script>
var arr=new Date();
console.log(typeof(arr));
console.log(arr.toString());
console.log(arr.__proto__.constructor.name);
console.log(Object.prototype.toString.call(arr));
</script>
效果: