标签:
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
标签:
原文地址:http://www.cnblogs.com/junwu/p/4825372.html