标签:ons object 操作符 prototype -o 基本 exp bool cti
(1)判断基本类型:
Object.prototype.toString.call(null); //”[object Null]” Object.prototype.toString.call(undefined); //”[object Undefined]” Object.prototype.toString.call(“abc”); //”[object String]” Object.prototype.toString.call(123); //”[object Number]” Object.prototype.toString.call(true); //”[object Boolean]”
(2)判断原生引用类型:
Function fn(){console.log(“abc”);} Object.prototype.toString.call(fn); //”[object Function]”
var date = new Date(); Object.prototype.toString.call(date); //”[object Date]”
var arr = [1,2,3]; Object.prototype.toString.call(arr); //”[object Array]”
var reg = /\w/g; Object.prototype.toString.call(reg); //"[object RegExp]"
function Person(name, age) { this.name = name; this.age = age; } var person = new Person("snow", 18); Object.prototype.toString.call(person); //"[object Object]"
console.log(person instanceof Person); //true
(3)判断原生JSON对象:
var isNativeJSON = window.JSON && Object.prototype.toString.call(JSON); console.log(isNativeJSON); //”[object JSON]”
Object----Object.prototype.toString.call()方法的使用
标签:ons object 操作符 prototype -o 基本 exp bool cti
原文地址:https://www.cnblogs.com/snowstorm22/p/10286288.html