The value of this
is determined by how the function is called, not by how or where it is defined.
Since you are passing the function to some third party code (.then
), you have to be aware that it is not you who calls the function, but the third party code, and you won't have any control over how the function is called.
At some point the callback will most likely be called in the way that most functions are called, simply as
someFunction()
In that case, this
refers to the global object which happens to be window
in browsers (this
is undefined
if the function is in strict mode).
More information on MDN.