toString()方法,与call()方法结合;用来进行数据类型检测

 //toString()方法,与call()方法结合;用来进行数据类型检测
console.log(Object.prototype.toString.call([]));//'[object Array]'
console.log(Object.prototype.toString.call({}));//'[object Object]'
console.log(Object.prototype.toString.call("abc"));//'[object String]'
console.log(Object.prototype.toString.call(123));//'[object Number]'
console.log(Object.prototype.toString.call(new Date()));//'[object Date]'
console.log(Object.prototype.toString.call(/abc/));//'[object RegRxp]'
console.log(Object.prototype.toString.call(true));//'[object Boolean]'
console.log(Object.prototype.toString.call(function(){}));//'[object Function]

 

转载于:https://my.oschina.net/itly/blog/761000

你可能感兴趣的:(toString()方法,与call()方法结合;用来进行数据类型检测)