function checkType(content,Type){
return Object.prototype.toString.call(content) === `[object ${Type}]`
}
const flag = checkType('hello','String');
//--------------------------------
function checkType(Type){
return function(content){
return Object.prototype.toString.call(content) === `[object ${Type}]`
}
}
const flag = checkType('hello','String');
const util = {};
const types = ['String','Number','Boolean'];
types.forEach(type=>{
util['is'+type] = checkType(type);
});
javascript类型检测
最新推荐文章于 2022-10-18 17:38:52 发布