JavaScript and Objects


JavaScript is an object-oriented scripting language, which means it thinks in terms of objects, properties, and methods . Although you can do a lot of work in JavaScript without being aware of its object-oriented nature, you're always using JavaScript objects when you work in this language; and the more you know about them, the more the language will make sense.

In scripting terms, an object is a collection of attributes that describe it and actions that it can perform. The attributes are called properties ; the actions are called methods . Properties are similar to variables , only they're always associated with a particular object. Methods are similar to functions. An object and its properties and methods are referred to in JavaScript using dot syntax, like this:

 object.property  object.method() 

For a real-world analogy, think of your dog as an object. He has various attributes breed, fur color , size , and so forth. He also has actions that he is capable of performingbarking, running, jumping, whining. If your dog's name is Fido, his properties and methods would be referred to like this:

 fido.breed = schnauzer;  fido.color = gray;  fido.bark();  fido.run(); 

Objects can also contain other objectsagain, just like your dog contains a tail and four instances of the paw object. In dot syntax, objects contained within other objects are referred to like this:

 parent_object.child_object 

Just like your dog's tail would be referred to as

 fido.tail 

JavaScript comes with a set of built-in objects ready for your use. These include the Date object, String object, window object, document object, and others. Each object has its own properties and methods. When you use the window.alert() statement, you're actually calling on the alert() method of the Window object. When you use document.myForm.myTextField.value to collect the value of a text field, you're actually collecting the value property of an object named myTextField , which is the child of an object called myForm , which is the child of the document object. (The hierarchical structure of elements within a document is called the DOM, or Document Object Model, in JavaScript. Chapter 4 covers using the DOM for extension writing.)

When you start working with Dreamweaver extensions, you'll discover that Dreamweaver provides a whole series of objects specifically for writing extensions. These include the dreamweaver or dw object, the site object, and the dom object.



Dreamweaver MX Extensions
Dreamweaver MX Extensions
ISBN: 0735711828
EAN: 2147483647
Year: 2001
Pages: 141
Authors: Laura Gutman

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net