62 Part III . Document Objects Reference Calling
Saturday, September 15th, 200762 Part III . Document Objects Reference Calling these objects JavaScript objects is not entirely correct. These are really browser document objects: you just happen to use the JavaScript language to bring them to life. Some scripters of Microsoft Internet Explorer use the VBScript lan guage to script the very same document objects. Technically speaking, JavaScript objects apply to data types and other core language objects separate from the doc ument. The more you can keep document and core language objects separate in your head, the more quickly you can deal with browser brand compatibility issues. Hierarchy as road map For the programmer, the primary role of the document object hierarchy is to pro vide scripts with a way to reference a particular object among all the objects that a browser window can contain. The hierarchy acts as a road map the script can use to know precisely which object to address. Consider, for a moment, a scene in which you and your friend Tony are in a high school classroom. It s getting hot and stuffy as the afternoon sun pours in through the wall of windows on the west side of the room. You say to Tony, Would you please open a window? and motion your head toward a particular window in the room. In programming terms, you ve issued a command to an object (whether or not Tony appreciates the comparison). This human interaction has many advan tages over anything you can do in programming. First, by making eye contact with Tony before you speak, he knows that he is the intended recipient of the command. Second, your body language passes along some parameters with that command, pointing ever so subtly to a particular window on a particular wall. If, instead, you are in the principal s office using the public address system, and you broadcast the same command, Would you please open a window?, no one knows what you mean. Issuing a command without directing it to an object is a waste of time because every object thinks, That can t be meant for me. To accom plish the same goal as your one-on-one command, the broadcast command has to be something like, Would Tony Jeffries in Room 312 please open the middle win dow on the west wall? Let s convert this last command to JavaScript dot syntax form (see Chapter 4). Recall from the tutorial that a reference to an object starts with the most global point of view and narrows to the most specific point of view. From the point of view of the principal s office, the location hierarchy of the target object is room312.Jeffries.Tony You can also say that Tony s knowledge about how to open a window is one of Tony s methods. The complete reference to Tony and his method then becomes room312.Jeffries.Tony.openWindow() Your job isn t complete yet. The method requires a parameter detailing which window to open. In this case, the window you want is the middle window of the west wall of Room 312. Or, from the hierarchical point of view of the principal s office, it becomes room312.westWall.middleWindow This object road map is the parameter for Tony s openWindow()method. Therefore, the entire command that comes over the PA system is room312.Jeffries.Tony.openWindow(room312.westWall.middleWindow)
We recommend high quality webhost to host and run your jsp application: christian web host services.