Cannot read properties of undefined when chaining methods [duplicate]
Solution 1:
You are calling hasDiff
without binding it to the correct this
object. Since you have strict mode enabled, the this
that hasDiff
is referring to when invoked outside of a someObject.hasDiff(...)
syntax is then undefined
(without strict mode it would be the global object).
Instead of passing this.hasDiff
to isListEqualToRows
, you need to pass either this.hasDiff.bind(this)
or (item, row) => this.hasDiff(item, row)
.
Alternatively, add a thisArg
argument to isListEqualToRows
where you pass this
from the caller's scope and then invoke hasDiffFunction
as hasDiffFunction.call(thisArg, object, row)
instead of hasDiffFunction(object, row)
.
See also: How does the "this" keyword work?