Guest User

Untitled

a guest
Feb 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. /*
  2. Will return true for Plain objects and class instances, false for everything else
  3. */
  4.  
  5. const isObject = value => {
  6. const strVal = Object.prototype.toString.call(value);
  7. return strVal.split(' ')[1].replace(']', '') === 'Object';
  8. }
  9.  
  10. isObject(null); // false
  11. isObject('object') // false
  12. isObject(String('object')) // false
  13. isObject(class MyClass {}) // false
  14. isObject() //false
  15. isObject([]) // false
  16.  
  17. class MyClass {}
  18. class SubClass extends MyClass {}
  19.  
  20. isObject({}) // true
  21. isObject(new MyClass()) // true
  22. isObject(new SubClass()) // true
Add Comment
Please, Sign In to add comment