In Javascript, only function calls establish a new this
context. When you call foo.bar()
, within the bar
function, this
will be bound to foo
; when you call foo()
, inside it this
will be bound to window
. An object literal constructor is not a method call, so it does not affect this
in any way; it will still refer to whatever it was referring to outside of the object literal.