//有缺陷,JSON.stringify(obj)中,如果obj本來是空的,又繼承了一個非空的物件那麼結果也會是“{}” 1. JSON.stringify(obj) == '{}' 2. Object.keys(obj).length == 0 //錯誤,當物件為空Array,length為1,空arguments時,length為2 //具體參考https://github.com/arasatasaygin/is.js/blob/master/is.js 3. Object.getOwnPropertyNames(value).length == 0 4. 一個完備的方法 //出自https://github.com/sindresorhus/is/blob/master/source/index.ts function isPlainObject(obj){ let prototype; return Object.prototype.toString.call(obj) === '[object Object]' && (prototype = Object.getPrototypeOf(obj), prototype === null || prototype == Object.getPrototypeOf({})) }