2 * http://pettanr.sourceforge.jp/test/type.html
\r
3 * ビルトイン方の判定に使用する関数を集めたもの。ブラウザのネイティブな判定関数には不可解な挙動があるので、X.Type を使用するほうがよい。
\r
10 * Object か?判定する。typeof null === 'object' に対策済なので null は Object ではない。
\r
12 isObject : function( v ){
\r
13 return v && typeof v === 'object'; // typeof null === 'object' に対策
\r
18 isFunction : function( v ){
\r
19 return typeof v === 'function';
\r
22 * ie の XHR.open 等ビルトインオブジェクトか?判定する。
\r
24 isUnknown : function( v ){
\r
25 return typeof v === 'unknown';
\r
28 * Array か?判定する。argumnets 等のファイク Array は false なので注意。
\r
33 X_UA.IE < 5.5 || X_UA.NetFront < 4 ? // netfront3.4 は html に instanceof をすると error になる
\r
34 'return v&&v.push===Array.prototype.push' : // win ie5-, MacIE5.2
\r
36 'return v&&Object.prototype.toString.call(v)==="[object Array]"' :
\r
37 'return v instanceof Array'
\r
42 isBoolean : function( v ){
\r
43 return v === true || v === false;
\r
48 isString : function( v ){
\r
49 return typeof v === 'string'; // v === v + ''; // 文字列の加算は IE で遅いかも。
\r
54 isNumber : function( v ){
\r
55 return typeof v === 'number'; // v !== v || v + 0 === v;
\r
58 * finite か?判定する。isFinite( '123' ) === true に対策済。
\r
60 isFinite : function( v ){
\r
61 return typeof v === 'number' && isFinite( v );
\r
64 * NaN か?判定する。isNaN( 'NaN' ) === true に対策済。
\r
66 isNaN : function( v ){
\r
70 * HTMLElement か?判定する。
\r
75 ( X_UA.IE4 || X_UA.MacIE ) ?
\r
76 'return v&&v.tagName&&v.insertAdjacentHTML&&true' : // ie4 or MacIE5.23, v.all <- error
\r
78 'return v&&v.nodeType===1' : // instanceof not a function. netfront3.4 は html に instanceof をすると error になる
\r
79 window[ 'HTMLElement' ] ?
\r
80 'return v instanceof HTMLElement' :
\r
81 //window[ 'Element' ] ?
\r
82 // 'return v instanceof Element' : // error @ie8
\r
83 'return v&&v.appendChild&&v.nodeType===1'
\r
87 * new Image した場合に HTMLImageElement が作られるブラウザと,そうでないブラウザ(IE8-)がある
\r
91 if( v && v.constructor === window.Image ) return true;
\r
92 if( v && window.HTMLImageElement && v.constructor === window.HTMLImageElement ) return true; // ie6- は constructor が undef、HTMLImageElement が undef なので、HTMLElement の存在確認が必要
\r
93 if( X_UA.WebKit < 525.13 ){ // Safari3-
\r
94 if( v && v.src !== undefined && v.onload !== undefined && X.Type.isNumber( v.height ) && X.Type.isNumber( v.width ) && X.Type.isBoolean( v.complete ) ){
\r
101 isElementCollection : function(v) {
\r
102 return (Object.prototype.toString.call(v) === "[object HTMLCollection]");
\r
108 isNull : function( v ){
\r
112 * undefined か?判定する。
\r
114 isUndefined : function( v ){
\r
115 return v === void 0;
\r
119 console.log( 'X.Core.Type' );
\r