Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Will return true for Plain objects and class instances, false for everything else
- */
- const isObject = value => {
- const strVal = Object.prototype.toString.call(value);
- return strVal.split(' ')[1].replace(']', '') === 'Object';
- }
- isObject(null); // false
- isObject('object') // false
- isObject(String('object')) // false
- isObject(class MyClass {}) // false
- isObject() //false
- isObject([]) // false
- class MyClass {}
- class SubClass extends MyClass {}
- isObject({}) // true
- isObject(new MyClass()) // true
- isObject(new SubClass()) // true
Add Comment
Please, Sign In to add comment