var Regitem = ['\\d','[\\u4E00-\\u9FA5]','[a-z]','[A-Z]'];
var fun_item = ['obj_isNumber','obj_isChar','obj_isSmall','obj_isLarge'];
function goFunc(){
for(var i = 0 ; i < fun_item.length ; i++){
window[fun_item[i]] = (function(i){
return function(obj){
return new RegExp(Regitem[i],'g').test(obj);
}
})(i);
//实际上下面这个也是对的。这是为什么啊?为什么这里不用闭包?
window[fun_item[i]] = function(obj){
return new RegExp(Regitem[i],'g').test(obj);
}
}
}
goFunc();
跃然一笑
相关分类