参考:http://www.cnblogs.com/flyjs/archive/2012/02/20/2360504.html 一般Array属于数组但是不能识别为Array而是object此方法可以识别详细的类型 1. [代码] test.html !doctype htmlhtml lang="en" head meta charset="UTF
一般Array属于数组 但是不能识别为Array 而是 object 此方法可以识别详细的类型
1. [代码]test.html
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> </head> <body> <a href="http://www.cnblogs.com/flyjs/archive/2012/02/20/2360504.html"> 参考:http://www.cnblogs.com/flyjs/archive/2012/02/20/2360504.html</a> <script> 2016/5/12 /** * Returns internal [[Class]] property of an object * * Ecma-262, 15.2.4.2 * Object.prototype.toString( ) * * When the toString method is called, the following steps are taken: * 1. Get the [[Class]] property of this object. * 2. Compute a string value by concatenating the three strings "[object ", Result (1), and "]". * 3. Return Result (2). * * __getClass(5); // => "Number" * __getClass({}); // => "Object" * __getClass(/foo/); // => "RegExp" * __getClass(''); // => "String" * __getClass(true); // => "Boolean" * __getClass([]); // => "Array" * __getClass(undefined); // => "Window" * __getClass(Element); // => "Constructor" * */ function __getClass(object){ return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1]; }; var ary = new Array(); var x = __getClass(ary); alert(x); </script> </body> </html>