【jQuery api】 $.type(obj)

时间:2023-03-03 21:52:20

用来获取JavaScript数据类型[[Class]]的对象

 <!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
Is it a RegExp? <b></b>
<script>$("b").append( "" + jQuery.type(/test/) );</script> </body>
</html>
 Is it a RegExp? regexp
  • 如果对象是undefined或null,则返回相应的“undefined”或“null”。
    • jQuery.type( undefined ) === "undefined"
    • jQuery.type() === "undefined"
    • jQuery.type( window.notDefined ) === "undefined"
    • jQuery.type( null ) === "null"
  • 如果对象有一个内部的[[Class]]和一个浏览器的内置对象的 [[Class]] 相同,我们返回相应的 [[Class]] 名字。
  • jQuery.type( true ) === "boolean"
    • jQuery.type( 3 ) === "number"
    • jQuery.type( "test" ) === "string"
    • jQuery.type( function(){} ) === "function"
    • jQuery.type( [] ) === "array"
    • jQuery.type( new Date() ) === "date"
    • jQuery.type( new Error() ) === "error" // as of jQuery 1.9
    • jQuery.type( /test/ ) === "regexp"
    • 其他一切都将返回它的类型“object”。