
Objects, Methods, and PropertiesIn our definition of Javascript, we referred to it as an object-based, event drive scripting language. The object-based means that Javascript works with items known as objects. Objects are things in a browser, a window, a form field, a document, a frame, a submit button, etc. Objects have methods which are essentially tasks or functions that the object performs. For example, in the example below we use the Objects also have properties which are characteristics of the object. For example the Let's look at a non Javascript example to help understand objects, methods, and propreties. Consider a a pet like a cat or a dog. What are some functions or tasks that a cat object might perform? Cats eat, sleep, scratch, meow, run, hunt, and other things. In Javascript lingo, each of these verbs would be methods of the cat object. These methods would be written as:
cat.eat("cat food")
cat.sleep()
cat.scratch("furniture")
cat.meow()
Notice that methods have parentheses after them and that some methods require information within the parentheses. Informaton within a method's parentheses is known as the method parameter(s). A parameter is just additional information that a method needs to do its job. In the Javascript world the Objects also have properties. Our cat has properties like size, color, furlenght, breed, and others. These properties would be written as cat.size cat.color cat.furlength cat.breed If you cut your cat's fur you would write that as cat.furlength = "short". Roughly translated this means: set the furlength property of the cat object to "short". In the first example, we changed the Javascript has hundreds of objects, methods, and properites. See Client-Side JavaScript Reference at Netscape's site for more information on JavaScript's many objects, methods, and properties.
|