When Lodash isArrayLikeObject Rejects a NodeList
By default, the Lodash utility method
_.isArrayLikeObject returns true when
evaluated against a standard DOM NodeList because it is a
non-null object featuring an integer-based length property.
For _.isArrayLikeObject to reject a NodeList
and return false, the instance must fail either Lodash's
internal isObjectLike check or its isArrayLike
check. Below are the precise technical conditions required for
rejection.
How _.isArrayLikeObject Evaluates Values
Lodash defines _.isArrayLikeObject as:
function isArrayLikeObject(value) {
return isObjectLike(value) && isArrayLike(value);
}A standard NodeList normally satisfies both
prerequisites:
isObjectLike(value)ensurestypeof value === 'object'andvalue !== null.isArrayLike(value)ensuresvalue !== null,typeof value !== 'function', andisLength(value.length)istrue.
Explicit Rejection Conditions
For a DOM NodeList to return false, one of
the following explicit conditions must be met:
1. The
length Property Fails isLength Validation
Lodash validates the length property using the internal
isLength(value) predicate. A NodeList will be
rejected if its .length property is tampered with or
corrupted so that it violates any of the following constraints:
- Non-Integer Values: The
.lengthproperty is modified to a floating-point number (e.g.,nodeList.length = 2.5), failing thelength % 1 === 0integer check. - Negative Values: The
.lengthproperty is set to a negative number (length < 0). - Values Exceeding Safe Limits: The
.lengthproperty exceeds the maximum safe integer limit (nodeList.length > Number.MAX_SAFE_INTEGER, or9007199254740991). - Non-Numeric Types: The
.lengthproperty is deleted or assigned a non-number type, such as a string, boolean, object, orundefined. - Not a Number (NaN) or Infinity: The
.lengthproperty is set toNaN,Infinity, or-Infinity.
2. The
typeof Evaluation Returns 'function'
Lodash explicitly rejects any value where
typeof value === 'function', even if that value possesses a
valid .length property.
- In non-standard JavaScript runtimes, legacy browser engines, or
polyfilled DOM environments where host objects or callable instances
return
typeof nodeList === 'function',_.isArrayLikeObjectwill immediately evaluate tofalse. - Wrapping the
NodeListinside a Proxy or custom callable structure that mimics a function causes the same rejection.
3. The
Reference Is null or Fails Object Classification
The isObjectLike check requires the value to be both
non-null and typed as an object:
- Null Reference: If the DOM query (such as
document.querySelectorAll) returnsnullor the reference variable is cleared tonull, it failsisObjectLike. - Prototype Corruption / Coercion: If the
NodeListinstance is converted or coerced into a primitive (such as an empty string or symbol), it fails thetypeof value === 'object'check.