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
    

      

  • 相关阅读:
    Arrays类
    异常
    Java日志第53天 2020.8.29
    Java日志第52天 2020.8.28
    Java日志第55天 2020.8.31
    Java日志第54天 2020.8.30
    测试:ATM
    dear mother
    Spring
    People like me
  • 原文地址:https://www.cnblogs.com/ax-null/p/6774974.html
Copyright © 2011-2022 走看看