zoukankan      html  css  js  c++  java
  • js 判断类型

    var type = (function() {
    		var getType = function(o) { return Object.prototype.toString.call(o) };
    
    		return {
    			isNumber: function(o) { return getType(o)    === '[object Number]'; },
    			isBoolean: function(o) { return getType(o)   === '[object Boolean]';},
    			isString: function(o) {return getType(o)     === '[object String]';},
    			isFunction: function(o) {return getType(o)   === '[object Function]';},
    			isArray: function(o) { return getType(o)     === '[object Array]';},
    			isObject: function(o) { return getType(o)    === '[object Object]';},
    			isDate: function(o) { return getType(o)      === '[object Date]';},
    			isRegExp: function(o) { return getType(o)    === '[object RegExp]';},
    			isNull: function(o) { return getType(o)      === '[object Null]';},
    			isUndefined: function(o) { return getType(o) === '[object Undefined]'; }
    		};
    }());
    
    
    // test 
    var n = 2;
    var s = "hello";
    console.log(type.isNumber(n), type.isString(s));   // true true
    

      

  • 相关阅读:
    AVL树
    快速排序
    基数排序LSD_Radix_Sort
    归并排序
    JDBC连接池与工具类
    cookie的基础以及小案例
    javase基础4
    tomcat的request和response小案例
    javase基础3
    Servlet以及一个简单的登录案例
  • 原文地址:https://www.cnblogs.com/ax-null/p/6774974.html
Copyright © 2011-2022 走看看