First look at small right teacher is how to do
Check whether the object hasthen
andcatch
methods
There’s another way to do it
You can borrow the original toString method
Interesting prototyping approach
Object.prototype.toString.call(new RegExp())
"[object RegExp]"
Object.prototype.toString.call(new Date())
"[object Date]"
Object.prototype.toString.call(new String())
"[object String]"
Object.prototype.toString.call(new Number())
"[object Number]"
Object.prototype.toString.call(Math)
"[object Math]"
Object.prototype.toString.call(new Error())
"[object Error]"
Object.prototype.toString.call(Symbol())
"[object Symbol]"
Object.prototype.toString.call(' ')
"[object String]"
Object.prototype.toString.call(0)
"[object Number]"
Object.prototype.toString.call(/ ^ 1 $/)
"[object RegExp]"
Object.prototype.toString.call(new Boolean())
"[object Boolean]"
Object.prototype.toString.call(true)
"[object Boolean]"
Copy the code