Javascript native functions (from the Browser) are part of the Object window
and are global. This is the same as saying that the properties of window
are accessible in the global scope. That is, they can be used in any scope.
However, they may be overwritten, and therefore no longer available within a certain scope/function. For example:
console.log(window.location.hostname); // pt.stackoverflow.com
(function () {
var location = {};
location.hostname= 'fooooo';
console.log(location.hostname); // fooooo
console.log(window.location.hostname); // pt.stackoverflow.com
})();
in this case window.location.pathname
will access the property location
of window
. But if, within another scope, we declare a name variable pathname
then in that scope, pathname
will not be the same as window.pathname
.
So, if necessary we can always access the "original" via window
. The reason not to use window.pathname
always is to save characters basically.
Scope, perhaps?
– DontVoteMeDown