There is a incredible fact that JavaScript has on simple way to detect whether a value is on object.
There are some alternative way, but all of them with troubles.
typeof value === 'object'
,typeof
return'object'
fornull
, and return'function'
for functions and class.instanceof Object
, returnfalse
forObject.create( null, )
and module object.
import 'https://better-js.fenz.land/src/object/isObject.js';
Object.isPureObject( null, ); // false
Object.isPureObject( {}, ); // true
Object.isPureObject( Object.create( null, ), ); // true
Object.isPureObject( await import (url), ); // true
Object.isPureObject( new class {}(), ); // false
Object.isPureObject( ()=> {}, ); // false
Object.isPureObject( class {}, ); // false