The reason why there is nothing in this world is because someone has lost their memory.

— Wang Xiaobo, Temple of Longevity

Welcome to Star: Pocket-LoDash

Gitbook will also be updated with the warehouse. Gitbook address: Pocket-Lodash

Source code analysis

IsObjectLike source code is very short, as follows:

function isObjectLike(value) {
  return typeof value == 'object'&& value ! = =null
}
Copy the code

Using the Typeof operator, if the return value is object and the value is not null, it is considered a class object.

A quick word about the Typeof operator. Typeof returns following the following rules:

type The results of
Undefined ‘undefined’
Null ‘object’
Boolean ‘boolean’
Number ‘number’
String ‘string’
Symbol ‘symbol’
The host object Implemented by the host, but cannot be'undefined'.'boolean'.'number''string'
The function object ‘function’
Any other object ‘object’

When typeof is used, null returns object. When the typeof operator is used, null returns object.

In the original implementation of JavaScript, values in JavaScript were represented by a tag representing a type and actual data values. The type label of the object is 0. Since null represents a null pointer (0x00 on most platforms), the type label for NULL also becomes 0, and typeof NULL incorrectly returns “object”. (reference)

ECMAScript proposed a fix (via opt-in) but was rejected. This will result in typeof NULL === ‘object’.

It is also important to note that the specification does not return ‘undefined’, ‘Boolean ‘, ‘number’, and ‘string’, except document.all, which returns ‘undefined’. This is an implementation that does not follow the specification.

reference

  • MDN:typeof

License

CC BY-NC-ND 4.0

Finally, all articles will be simultaneously sent to the wechat public account, welcome to pay attention to, welcome to comment:

Akik The opposite corner