This simple fiddle shows properties of Window object:
var obj = this; // object Window
var variables = "";
for (var name in obj) {
if (obj.hasOwnProperty(name)) {
variables += name + " : " + obj[name] + "<br/>";
}
}
document.writeln(variables);
When this script is called directly with no wrap it shows this result:
window : [object Window]
document : [object HTMLDocument]
InstallTrigger : [object Object]
obj : [object Window]
variables : window : [object Window] document : [object HTMLDocument] InstallTrigger : [object Object] obj : [object Window]
name : name
getInterface : function getInterface() { [native code] }
location : http://fiddle.jshell.net/_display/
navigator : [object Navigator]
But when called onload it shows only:
window : [object Window]
document : [object HTMLDocument]
InstallTrigger : [object Object]
getInterface : function getInterface() { [native code] }
location : http://fiddle.jshell.net/4x3Tx/2/show/
navigator : [object Navigator]
And so the question is obvious: can somebody explain why are obj, variables and name variables missing from the second fiddle results? In both cases the obj refers to Window object.
When you run the code “onLoad”, it is put inside a function and assigned to
window.onload:obj,variablesandnameare now local to that function, not global and hence are not properties of thewindowobject.