Suppose I have an object:
var o = {
prop: 3,
method: function() {return this.prop}
}
I was expecting this
(o.method)()
to return undefined
, however it returned 3
meaning that this
is set to o
inside method
. Why is it so? If you evaluate (o.method)
separately, it evaluates to a standalone function, so I expected this
to reference global object. Why, for example, the difference exists here:
(o.method)() vs (o.method || true)()
I know that o.method()
will use o
as context, the question is specifically about accessing the function first like this (o.method)
and then calling it.