js判断数据类型

 1 //是否是json类型
 2 function isJson(data){
 3     return (typeof data === 'object' && data+'' === '[object Object]');
 4 }
 5 //是否是数组
 6 function isArray(data){
 7     return data instanceof Array;
 8 }
 9 //是否是简单类型
10 function isSimple(data){
11     if(typeof data === 'number' || typeof data === 'string' || typeof data === 'boolean'){
12         return true;
13     }else{
14         return false;
15     }
16 }
17 //是否是引用类型
18 function isRef(data){
19     return !isSimple(data)
20 }

posted @ 2015-12-02 20:50  liuwt365  阅读(161)  评论(0编辑  收藏  举报