The University of Texas at Austin- What Starts Here Changes the World
Services Navigation


Objects, Methods, and Properties

In 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 window object and the prompt method of that object. Similarly we call the write method of the document object.

Objects also have properties which are characteristics of the object. For example the document object has a property called bgColor that describes the background color of that object.

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 write method of the document object needs to know what to write so the method has a parameter that tells it what to write. Similarly the parameter of the prompt method tells the method what to display in the dialog box

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 bgColor property of the document object to be the color that the user entered.

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.

 


  Updated 2006 February 12
  Comments to www@www.utexas.edu