I’m looking at a complex bit of JavaScript, which is doing all sorts of runtime/dynamic manipulation of objects and scripts. In the process, I’m learning all sorts of minutiae about Javascript and its idiosyncrasies.
This one has me stumped, though. Is there ever a situation where
window !== this.window; //true
In other words, when would you ever write this.window instead of straight out window?
Sure, whenever
thisrefers to an object without a.windowproperty or with a.windowproperty that doesn’t point to the global object (assuming a browser environment wherewindowis the global).When
thisrefers to an object where a.windowproperty is anticipated not being a reference to the global.