寫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