$.type()

このエントリーをはてなブックマークに追加

$.type()はJavaScriptのオブジェクトの型を判定するメソッドです。

$.type()は次のようなプロセスで判定を行ないます。

まず、”undefined” か “null” かの判定を行ない、その値を返します。

$.type( undefined ) === "undefined"
$.type() === "undefined"
$.type( window.notDefined ) === "undefined"
$.type( null ) === "null"

次に、ECMAScriptで定義されているオブジェクトかどうかの判定を行ないます。

$.type( true ) === "boolean"
$.type( new Boolean() ) === "boolean"
$.type( 3 ) === "number"
$.type( new Number(3) ) === "number"
$.type( "test" ) === "string"
$.type( new String("test") ) === "string"
$.type( function(){} ) === "function"
$.type( [] ) === "array"
$.type( new Array() ) === "array"
$.type( new Date() ) === "date"
$.type( new Error() ) === "error"
$.type( /test/ ) === "regexp"

これら以外は”object”を返します。

jQuery 1.4.3での追加/変更

$.type()はjQuery 1.4.3で追加されたメソッドです。

jQuery 1.9.0での追加/変更

jQuery 1.9.0よりErrorオブジェクトの判定が追加されました。

参考URL

jQuery.type() | jQuery API Documentation

登録日 : 2013年06月09日 最終更新日 : 2013年6月9日

同じカテゴリー(Utilities)のエントリー

検索

スポンサードリンク

バージョン

リファレンス