0

According to the spec there are only 6 types, 5 of which are native ( Null, Undefined, Number, String, Boolean ) and 1 which is of type Object.

Googled it.

It appears that typeof fails for null and detects it as an object.

It also seems that toString() will report Object descendants as their descendant type, for example RegExp, Function, etc.

I don't want the descendant type, I want RegExp, Function, etc. reported as Object.

I basically want to detect true ES5 Objects.

  • [_.isObject](https://github.com/lodash/lodash/blob/96430fd5458b20dab73e4b11ee71fb99012f5759/dist/lodash.core.js#L2747) – Bryan Chen Jun 27 '16 at 02:55
  • what's the point of this novel grouping? – dandavis Jun 27 '16 at 03:00
  • `!{string:1,number:1,boolean:1,undefined:1}[typeof value]` – dandavis Jun 27 '16 at 03:03
  • The answer is close but not correct, why is this marked as a duplicate. I'm looking for **objects as defined by ES5** –  Jun 27 '16 at 03:06
  • @Bergi, the question you referenced does not directly address thie question being asked here. – Femi Jun 27 '16 at 03:44
  • @MjrKusanagi [This answer](http://stackoverflow.com/a/22482737/1048572) to the duplicate question does exactly address brannon's problem and provides all known solutions for it. – Bergi Jun 27 '16 at 03:55
  • @Bergi, thanks. I see that now, sorry. – Femi Jun 27 '16 at 04:00
  • @brannon .. `function es5_type(query){return (query===null ? "null" : typeof query==="function" ? "object" : typeof query);}` – Femi Jun 27 '16 at 04:05
  • @Bergi - The question is vague that is why it has a gazillion answers. I think I found the second law of thermodynamics some where in there ... but no ... close my question which is more specific ( better ). –  Jun 29 '16 at 17:13

1 Answers1

-3

Taken from angularjs:

function isObject(value) {
  // http://jsperf.com/isobject4
  return value !== null && typeof value === 'object';
}
pgreen2
  • 3,601
  • 3
  • 32
  • 59