Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. The Head/Global Object > The Head Object Is Implied and Typically Not Refere...

The Head Object Is Implied and Typically Not Referenced Explicitly

Typically a reference to the head object is not used because it is implied. For example, in the browser environment, window.alert and alert() are essentially the same statement. JavaScript fills in the blanks here. Because the window object (i.e., the head object) is the last object checked in the scope chain for a value, the window object is essentially always implied. Below, we leverage the alert() function which is contained in the global scope.

Live Code

<!DOCTYPE html><html lang="en"><body><script>

var foo = { // window is implied here, window.foo
   fooMethod: function() {
       alert('foo' + 'bar'); // window is implied here, window.alert
       window.alert('foo' + 'bar'); /* window is explicitly used, 
                                    with the same effect */
   }
}

foo.fooMethod(); // window is implied here, window.foo.fooMethod()

</script></body></html>

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint