If I open an empty page and I run the following command in javascript console I obtain the same result:
>>> this
DOMWindow
>>> self
DOMWindow
>>> window
DOMWindow
>>> window.self
DOMWindow
What do they refer to? …the same object or what else?
windowis the reference to the current browser’s window the script executes in.window.selfis obviously a self-reference of that within itself. And sinceselfhere is a property of the global objectwindow, it can also be accessed as if it was a “global” variable itself: justself.So the last three are under most circumstances indeed the same thing.
thishowever is completely different: it’s a variable pointing to the current scope. If you execute the following code in the console:thiswill be pointing to themyPackageobject (the scope ofmethod).