オブジェクトの本当の種類を調べる

書式

jQuery.type(obj)

obj : 調べる対象

説明

オブジェクトの本当の種類を調べるにはjQuery.type()を使います。パラメータには調べたいオブジェクトを指定します。関数であればfunction、数値であればnumber、正規表現オブジェクトであればregexpといった文字列が返されます。

サンプルコード [実行]

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="main.css" type="text/css" media="all">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript"><!--
$(function(){
var txt = jQuery.type(123)+"<br>";
txt += jQuery.type("sample")+"<br>";
txt += jQuery.type(new Array)+"<br>";
txt += jQuery.type(new Date)+"<br>";
txt += jQuery.type(function(){})+"<br>";
txt += jQuery.type(new RegExp("jq"))+"<br>";
$("#result").html(txt);
});
// --></script>
</head>
<body>
<h1>オブジェクトの本当の種類を返す</h1>
<div id="result"></div>
</body>
</html>