Some Help Understanding Window Object
Solution 1:
The window object is effectively two things:
The global object for browser-based JavaScript. All of the native objects and methods (
Array,String,setTimeout()) and anything you declare outside of any function's scope goes in thewindowobject. To test this, try opening a JavaScript console and checking this out:window.String === String// Returns trueThe
windowobject also deals with the browser window.window.innerWidthis the window's width;window.onresizeis a function that is triggered on the window resize. Because it's the "topmost" object, you can also say things likeinnerWidthto get the window's width.
In general, it's a good practice to refer to write window.location instead of just location. Even though they'll work a lot of the time, you'll sometimes run into situations like this (which you don't want!):
function something() {
var location = 'the moon';
location.reload(); // Should be window.location.reload()
}
In the above example, you might've meant to refresh window.location instead of the location scoped inside this function.
And that's the window object!
Post a Comment for "Some Help Understanding Window Object"