为什么用Object.prototype.toString.call(obj)检测对象类型?
Posted 童彪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么用Object.prototype.toString.call(obj)检测对象类型?相关的知识,希望对你有一定的参考价值。
console.log(Object.prototype.toString.call("jerry"));//[object String]
console.log(Object.prototype.toString.call(12));//[object Number]
console.log(Object.prototype.toString.call(true));//[object Boolean]
console.log(Object.prototype.toString.call(undefined));//[object Undefined]
console.log(Object.prototype.toString.call(null));//[object Null]
console.log(Object.prototype.toString.call({name: "jerry"}));//[object Object]
console.log(Object.prototype.toString.call(function(){}));//[object Function]
console.log(Object.prototype.toString.call([]));//[object Array]
console.log(Object.prototype.toString.call(new Date));//[object Date]
console.log(Object.prototype.toString.call(/\d/));//[object RegExp]
function Person(){};
console.log(Object.prototype.toString.call(new Person));//[object Object]
以上是关于为什么用Object.prototype.toString.call(obj)检测对象类型?的主要内容,如果未能解决你的问题,请参考以下文章