6.2 Objects and methods
Objects are a natural way of thinking about the world and of writing scripts that manipulate XHTML documents. Java Script uses objects to perform many tasks and therefore referred to as and ovject-based programming language.
It facilitates objects to be defined ad used in the documents. All objects in the real world have attributes such as size, shape color, weight and the like; and they all exhibit behaviours, for example a ball rolls, bounces, inflates and deflates, a baby cries, sleeps, crawls and walks. Humans learn about objects by studying their attributes and observing their behaviors. Objects encapsulate data(properties) and methods. A java script object is a composition of its properties and method. For example a student has name, number, mark1, mark2, as its properties and total calculation and average are methods.
Java script handles the HTML documents and the related objects such as windows, forms and screen in a specific hierarchy. This hierarchy is called the Document Object Model (DOM) which is directly related to the browsers. The properties of the object covered in the DOM get their values supplied by the browser.
The following table shows the most commonly used Java Script objects.
Table 6.1. Hierarchy of Objects their Properties and Methods.
Objects | properties | Methods |
---|---|---|
Window | Default Status | Alert |
Frames | Blur | |
Opener | Close | |
Parent | Confirm | |
Scroll | Open | |
Self | Focus | |
Status | Prompt | |
Top | ClearTimeout | |
Window | Set Timeout | |
Frame | Defaultstatus | Alert |
Frames | Blur | |
Opener | Close | |
Parent | Confirm | |
Scroll | Open | |
Self | Focus | |
Status | Prompt | |
Top | clearTimeout | |
Window | setTimeout | |
Location | Hash | Reload |
Host | Replace | |
Hostname | ||
Href | ||
Pathname | ||
Protocol | ||
Search | ||
History | Length | Black |
Forward | ||
go | ||
Navigator | AppCodename | JavaEnabled |
AppName | ||
AppVersion | ||
mimerType | ||
Plugin | ||
userAgent | ||
Document | alinkColor | Clear |
Area | Close | |
Anchors | Open | |
Applets | Write | |
Bgcolour | writeIn | |
Cookie | ||
Fgcolor | ||
Cookie | ||
Fgcolor | ||
Forms | ||
Images | ||
lastModified | ||
linkColor | ||
Links | ||
location | ||
Referrer | ||
Title | ||
vlinkColor | ||
Image | Border | None |
Complete | ||
Height | ||
Hspace | ||
Lowsrc | ||
Src | ||
Vspace | ||
Width | ||
Form | action | onSubmit |
Elements | OnReset | |
Encoding | ||
FileUpload | ||
Method | ||
Name | ||
Target | ||
Text | Defaultvalue | OnBlur |
Name | OnFocus | |
Type | OnChange | |
value | OnSelect |
JavaScript also supports built in objects such as Array, Date and string.
Related Posts:
Subscribe Here (or)
In JavaScript you can define your own objects. In addition, you can assign methods and properties to each object, pre-written or self-defined.