Object Properties

I am getting the gist of the hierarchy of JavaScript, but Chapter 3 goes more indepth on this. At this time, I know document is an object, and write is a method. I know that methods do something to objects. I understand how to write the object-and-method format in JavaScript. There is a another aspect of the JavaScript hierarchy: object properties, which is like a subsection of an object. Properties hold specific characteristics about the object. For example, properties of a document can be background color, text color and location. Besides the document object, we have other objects:

In the HTML box below, the scripts cover these four objects and many of their properties:

HTML file: Displayed by browser:
<BODY>

<!--Writing document Object Properties-->
<SCRIPT LANGUAGE="javascript">
document.write("The background color of this page is <B>"
+document.bgColor+ "</B>.")
document.write("<BR>The foreground (or text) color of this page is <B>" +document.fgColor+ "</B>.")
document.write("<BR>The link color of this page is <B>"
+document.linkColor+ "</B>.")
document.write("<BR>The active link color of this page is <B>"
+document.alinkColor+ "</B>.")
document.write("<BR>The visited link color of this page is <B>"
+document.vlinkColor+ "</B>.")
document.write("<BR>The URL of this page is <B>"
+document.location+ "</B>.")
document.write("<BR>The page you were at before this page was <B>" +document.referrer+ "</B>.")
document.write("<BR>Here's what's written in the TITLE of this page: <B>" +document.title+ "</B>.")
document.write("<BR>The document was last modified: <B>"
+document.lastModified+ "</B>.")
</SCRIPT>

<!--Writing navigator Object Properties-->
<SCRIPT LANGUAGE="javascript">
document.write("You are using <B>" +navigator.appName+ ".</B><BR>")
document.write("It is version " +navigator.appVersion+ ".<BR>")
document.write("Its code name is " +navigator.appCodeName+ ".<BR>")
document.write("It sends the header " +navigator.userAgent+ "." );
</SCRIPT>

<!--Writing history Object Properties-->
<SCRIPT LANGUAGE="javascript">
document.write("You have visited " +history.length+ " pages before this one.")
</SCRIPT>

<!--Writing location Object Properties-->
<SCRIPT LANGUAGE="javascript">
document.write("The name of this location is <B>" + location.host + "</B>." )
</SCRIPT>

<SCRIPT LANGUAGE="javascript">
document.write("The name of this location is <B>" + location.hostname + "</B>." )
</SCRIPT>

</BODY>

Some of the properties used here might be old (I know I am not using Netscape!) but that is not an issue right now. The issue is to learn about the format of properties in the script. The format for calling a property is the same as the object-and-method format (object name, a dot, and then property). The difference is that there is no parentheses after the property. Methods affect objects, but properties already exist. You just want the property and nothing else, so there is no need for parentheses instance. Later, we'll learn the parentheses are used to pass data around, but properties have nothing that can be passed to it, so no need for the brackets. Now, over the next few pages, we will deconstruct these scripts to learn and understand them.

BackTable of ContentsNext