In JavaScript the this
object is really based on how you make your function calls.
In general there are three ways to setup the this
object:
someThing.someFunction(arg1, arg2, argN)
someFunction.call(someThing, arg1, arg2, argN)
someFunction.apply(someThing, [arg1, arg2, argN])
In all of the above examples the this
object will be someThing
.
Calling a function without a leading parent object will generally get you the global object which in most browsers means the window
object.