1.判断数值为空
function isEmpty(value) {
return (
value === null || value === undefined ||
(typeof value === 'object' && Object.keys(value).length === 0) ||
(typeof value === 'string' && value.trim().length === 0)
)
}
2.判断空函数体
之前在网上都找不到好用的,只能自己写一个
function isEmptyFunction(func){
if(typeof func != 'function'){
console.log('请输入函数')
return false
}
let str = func.toString().replace(/\s+/g,'')
str = str.match(/{.*}/g)[0]
return str === '{}'
}