Let's consider the scenario with an object:
var o = {
prop: 3,
method: function() {return this.prop}
}
My expectation was that calling
(o.method)()
would result in undefined
, but instead it returned 3
, indicating that the reference of this
is set to o
inside the method
. Why does this happen? When I evaluate (o.method)
separately, it appears as a standalone function, leading me to believe that this
would refer to the global object. The distinction becomes apparent in the following comparison:
(o.method)() vs (o.method || true)()
I am aware that o.method()
will use o
as the context; my question specifically pertains to initially accessing the function like this (o.method)
before invoking it.