`

js判斷變量類型

 
阅读更多

 

isNull: function(a){
02     return a === null;
03 },
04 isUndefined: function(a){
05     return a === undefined;
06 },
07 isNumber: function(a){
08     return typeof a === 'number';
09 },
10 isString: function(a){
11     return typeof a === 'string';
12 },
13 isBoolean: function(a){
14     return typeof a === 'boolean';
15 },
16 isPrimitive: function(b){
17     var a = typeof b;
18     return !!(b === undefined || b === null || a == 'boolean' || a =='number' || a == 'string');      
19 },
20 isArray: function(a){
21     return proto_obj.toString.call(a) === '[object Array]';
22 },
23 isFunction: function(a){
24     return proto_obj.toString.call(a) === '[object Function]';
25 },
26 isPlainObject: function(o){
27     if (!o || o === win || o === doc || o === doc.body) {
28         return false;
29     }
30     return 'isPrototypeOf' in o && proto_obj.toString.call(o) === '[object Object]';       
31 },
32 isWindow: function(o){
33     return o && typeof o === 'object' && 'setInterval' in o;
34 },
35 isEmptyObject: function(o){
36     for(var in o) {
37     return false;
38     }
39     return true;
40 }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics