Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
There are typically two ways to reference the head object. The first
way is to simply reference the name given to the head object (e.g., in a
web browser this would be window). The
second way is to use the this keyword
in the global scope. Each of these are detailed in the code
below.
<!DOCTYPE html><html lang="en"><body><script> var foo = 'bar'; windowRef1 = window; windowRef2 = this; console.log(windowRef1, windowRef2); // logs reference to window object console.log(windowRef1.foo, windowRef2.foo); // logs 'bar', 'bar' </script></body></html>
In the code above, we explicitly store a reference to the head
object in two variables that are then used to gain access to the global
foo variable.