/**
* 判断类型文件
*
* 还在使用Object.prototype.toString.call吗?
* 如果你需要判断很多的类型,建议使用以下方法
*
*/
export const toString = Object.prototype.toString;
export const is = (val, type) => toString.call(val) == `[object ${type}]`
//判断是否是数字类型
export const isNumber = (val) => is(val, "Number");
//判断是否是字符类型
export const isString = (val) => is(val, "String");
//判断是否为boolean类型
export const isBoolean = (val) => is(val, "Boolean");
// 判断 是undefined
export const isUnDef = (val) => typeof val == 'undefined'
//判断是否是数组
export const isArray = (val) => val && Array.isArray(val);
//判断是否是对象
export const isObject = (val) => val !== null && toString.call(val) === `[object Object]`;
//判断是否为函数
export const isFunction = (val) => typeof val === "function&
还在使用Object.prototype.toString.call判断的类型?分享一个超好用的判断类型js文件
于 2023-04-21 14:50:16 首次发布