JavaScript Babble - It's really not that Bad.
It's easy to get spooked with JavaScript's terminology. Don't be. Many terms can be seen as short-hand for its functions and you'll find the more you work with JavaScript the more familiar these will become.
JavaScript is highly case sensitive so GetData and getData are seen as two different words to JavaScript and it will treat them differently. All properties, methods and variable names are case sensitive so that's why you must copy any JavaScript code exactly as it is written even down to the capital and lower case letters. If you don't, the incorrectly typed commands may trigger a syntax error.
Here are some common terms associated with JavaScript and their meanings:
Object
An object is simply a thing, like this magazine, the book on your desk,
your computer or a pen. A Web page is made up of objects such as its graphics, text boxes,
links, radio buttons and text. JavaScript can read these objects and give you information
about what they contain and you can change the values in them on the fly.
In our clock the text box on the form is an object whose value is changed every 10 seconds by the JavaScript code. Other objects are the browser itself, the current browser window, the text on the page etc.
Method
A method is a function that works on a particular object. In our example we
have created an instance of the date object and called it currentTime. The methods
getHours and getMinutes are functions that only work with date objects.
Each object type has various methods associated with it. JavaScript contains a range of methods which include methods for changing font size and colour, which work with the string (or text) object, and mathematical ones such as round, sqrt and max which work with the Math object etc.
Event
An event is an action which happens to an object and which is usually
initiated by the user. For example when you move your mouse over a graphic the mouseover
event is triggered and when you click a link with your mouse button, the click event is
triggered. In JavaScript you can specify lines of programming code to be run when any one
of these events is triggered.
In the clock example, we have used an event which is not triggered by the user to run the clock. The event is the load event which is triggered when the browser finishes loading the page.
When you use events in JavaScript you must use event handlers which are HTML tags to run your code. The event handler in the clock example is in the HTML BODY tag. The event handler identifies the event to look out for and the script to be run when the event happens. In our example the event handler is: ltBODY OnLoad = "setTime()"gt. This waits for the page to finish loading and when this happens it calls the setTime function.
Properties
A property is an attribute of an object. This magazine (an object) has
properties such as a title, page size and paper colour. JavaScript objects have properties
too, for example the current Web page has properties such as visited link colour and
background colour. You can read the current values of these properties in your code and,
in some circumstances alter them too.
For example the property of the Navigator object which tells you the name of the current browser is one you can only read, but not write to. Other properties such as the checked property of a check box can be read from and written to, so that you can check and uncheck a checkbox within your JavaScript code.
Variables
A variable is a place where you can store data that you will use later on
in a program. Each variable must have a name and, in JavaScript, this name may not include
spaces or hyphens or most punctuation symbols, and must begin with a letter of the
alphabet or an underscore (_). JavaScript has some 'reserved words' which you may not use
as variable names. Once you have named a variable you can use this name to refer to its
value in your program and you can change its value too.
Reserved words
Reserved words are words that JavaScript 'reserves' for its own use, such
as 'do', 'if', 'else', 'true', 'false' etc. These words have their own special tasks to
perform which is why you are not allowed to use them as variable names.
Web resources
The Web abounds with JavaScript resources. One popular site is the
Cut-n-Paste JavaScript site at:
http://www.infohiway.com/javascript/
Also visit Yahoo's JavaScript Index at:
http://www.yahoo.com/Computers_and_Internet/Programming_Languages/JavaScript/
And, finally, Netscape's authoring guide:
http://home.netscape.com/eng/mozilla/Gold/authoring/navgold.htm
Books
These books will be a valuable addition to your library:
For beginners:
JavaScript Interactive Course, Waite Group Press
For more accomplished users:
Special Edition, Using JavaScript, by M Reynolds and A Wooldridge.