OSDN Git Service

43316dd8e6e7371fc8ebadcc6299e69ee8016b0a
[pettanr/clientJs.git] / 0.6.x / js / 00_core / 02_XType.js
1 /*\r
2  * http://pettanr.sourceforge.jp/test/type.html\r
3  * \r
4  * need xua\r
5  */\r
6 \r
7 X.Type = {\r
8         isObject : function(v) {\r
9                 return v !== null && typeof v === 'object';\r
10         },\r
11         \r
12         isFunction : function(v) {\r
13                 return typeof v === 'function';\r
14         },\r
15         isArray :\r
16                 new Function( 'v',\r
17                         X.UA.IE < 5.5 ? 'return v && v.push === Array.prototype.push;' : // win ie5-, MacIE5.2\r
18                         X.UA.IE ? 'return v && Object.prototype.toString.call(v) === "[object Array]"' :\r
19                                 'return v instanceof Array;'\r
20                 ),\r
21                 \r
22         isBoolean : function(v) {\r
23                 return typeof v === 'boolean'; // v === true || v === false;\r
24         },\r
25         isString : function(v) {\r
26                 return typeof v === 'string';\r
27         },\r
28         isNumber : function(v) {\r
29                 return typeof v === 'number';\r
30         },\r
31         isFinite : function(v){\r
32                 return typeof v === 'number' && isFinite(v);\r
33         },\r
34         isNaN : function(v){\r
35                 return typeof v === 'number' && v !== v;\r
36         },\r
37         isHTMLElement :\r
38                 // ie4 or MacIE5.23\r
39                 ( X.UA.IE4 || X.UA.MacIE ) ? (function(v){ return v && v.tagName && v.all;}) :\r
40                 window['HTMLElement'] ? (new Function('v', 'return v instanceof HTMLElement')) :\r
41                 (function(v){ return v && v.nodeType === 1 && v.appendChild;}),\r
42         /*\r
43         isElementCollection : function(v) {\r
44                 return (Object.prototype.toString.call(v) === "[object HTMLCollection]");\r
45         },\r
46         */\r
47         isNull : function(v) {\r
48                 return v === null;\r
49         },\r
50         isUndefined : function(v) {\r
51                 return typeof v === 'undefined';\r
52         }\r
53 };\r
54 \r
55 console.log( 'X.Core.Type' );\r