如何改写jQuery判断js对象详细类型的底层库写法为长尾词?

2026-04-06 10:401阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计285个文字,预计阅读时间需要2分钟。

如何改写jQuery判断js对象详细类型的底层库写法为长尾词?

参考:http://www.cnblogs.com/flyjs/archive/2012/02/20/2360504.

通常,Array属于数组类型,但无法识别为Array而是Object。此方法可以识别详细的类型:

如何改写jQuery判断js对象详细类型的底层库写法为长尾词?

1. [代码]

参考:www.cnblogs.com/flyjs/archive/2012/02/20/2360504.html

一般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="www.cnblogs.com/flyjs/archive/2012/02/20/2360504.html"> 参考: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>

本文共计285个文字,预计阅读时间需要2分钟。

如何改写jQuery判断js对象详细类型的底层库写法为长尾词?

参考:http://www.cnblogs.com/flyjs/archive/2012/02/20/2360504.

通常,Array属于数组类型,但无法识别为Array而是Object。此方法可以识别详细的类型:

如何改写jQuery判断js对象详细类型的底层库写法为长尾词?

1. [代码]

参考:www.cnblogs.com/flyjs/archive/2012/02/20/2360504.html

一般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="www.cnblogs.com/flyjs/archive/2012/02/20/2360504.html"> 参考: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>