1判断数据类型
var gettype = function(type){ return function(obj){ return Object.prototype.toString.call(obj) == '[object '+ type +']'; } } var isString = gettype('String'); console.log(isString('123'));//true
应用循环批量注册isType函数
var Type={}; for(var i=0,type;type=['String','Array','Number'][i++];){ (function(type){ Type['is' + type] = function(obj){ return Object.prototype.toString.call(obj) === '[object '+ type +']'; } })(type); } console.log(Type.isArray( [] ));//true