Object.prototype.toString.call()进行类型判断

 1 <!doctype html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6 </head>
 7 <body>
 8 <script>
 9     var a1 = {
10         c:1,
11         d:2
12     }
13     var a2 = [1,2,3];
14     var a3 = 2;
15     var a4 = "wwww";
16     var b1 = Object.prototype.toString.call(a1);
17     var b2 = Object.prototype.toString.call(a2);
18     var b3 = Object.prototype.toString.call(a3);
19     var b4 = Object.prototype.toString.call(a4);
20     var b5 = Object.prototype.toString.call(null);
21     var b6 = Object.prototype.toString.call(NaN);
22     console.log(b1);
23     console.log(b2);
24     console.log(b3);
25     console.log(b4);
26     console.log(b5);
27     console.log(b6);
28     console.log(NaN)
29 </script>
30 </body>
31 </html>

 

坚持下去就能成功
原文地址:https://www.cnblogs.com/suoking/p/5000856.html