写js常常会遇到非空判断,看了你不就像风同样的文章html
本身没有作总结,特意转载。颇有帮助spa
function isEmpty(obj) { // 检验 undefined 和 null if (!obj && obj !== 0 && obj !== '') { return true; } if (Array.prototype.isPrototypeOf(obj) && obj.length === 0) { return true; } if (Object.prototype.isPrototypeOf(obj) && Object.keys(obj).length === 0) { return true; } return false; }
做者:像风同样prototype