- (function(win){
- var type = {
- str : '[object String]',
- arr : '[object Array]',
- num : '[object Number]',
- func: '[object Function]',
- obj : '[object Object]',
- bool: '[object Boolean]',
- date: '[object Date]',
- unde: '[object Undefined]',
- nil : '[object Null]'
- }
- function getType(arg){
- return Object.prototype.toString.call(arg);
- }
- var fn = function(){}
- fn.prototype = {
- isDate:function (arg){
- return getType(arg)===type.date;
- },
- isNull:function (arg){
- return getType(arg)===type.nil;
- },
- isNum:function (arg){
- return getType(arg)===type.num;
- },
- isFunc:function (arg){
- return getType(arg)===type.func;
- },
- isArr:function (arg){
- return getType(arg)===type.arr;
- },
- isObj:function (arg){
- return getType(arg)===type.obj;
- },
- isUndefined:function (arg){
- return getType(arg)===type.unde;
- },
- isBool:function (arg){
- return getType(arg)===type.bool;
- },
- isStr:function (arg){
- return getType(arg)===type.str;
- }
- }
- win.xg = new fn();
- })(window);
- //该片段来自于http://www.codesnippet.cn/detail/2601201511625.html
来源: http://www.codesnippet.cn/detail/2601201511625.html