|
|
|
|
Begin With Properties, Methods, Handling Events, Values, Variables
Objects have properties. A cat has fur, the computer has a keyboard, and the bicycle has wheels. In the JavaScript world, a window has a title, and a form has a check box. Properties can modify objects, and the same property can apply to completely different objects. Let's say that you have a property called empty. It's okay to use empty wherever it applies, so you could say that both the cat's tummy is empty and the cat's bowl is empty. Note that the computer's keyboard and the bicycle's wheels aren't only properties; they are also objects in their own right, which can have their own properties. So objects can have sub-objects.
The things that objects can do are called methods. Cats purr, computers crash, and bicycles roll. JavaScript objects also have methods: buttons click(), windows open(), and text can be selected(). The parentheses signal that we're referring to a method, rather than a property. It might help to think of objects and properties as nouns, and methods as verbs. The former are things, and the latter are actions that those things can do, or have done to them.
Events are actions that the user performs while visiting your page. Submitting a form and moving a mouse over an image are two examples of events. JavaScript deals with events with commands called event handlers. An action by the user on the page triggers an event handler in your script. In JavaScript, if the user clicks on a button, the onClick() event handler will take note of the action and perform whatever duties it was assigned. The twelve JavaScript event handlers are listed below :
In JavaScript, a piece of information is a value. There are different kinds of values; the kind you're most familiar with are numbers. A string value is a word or words enclosed in quotes. Variables contain values. For example, the variable myName is assigned the string "Barbie." Another way to write this is myName = "Barbie". The equals sign can be read as "is set to." In other words, the variable myName now contains the value "Barbie :". JavaScript is case sensitive. This means that myname is not the same as myName, and neither is the same as MyName. Variable names cannot contain spaces or other punctuation. They also can't be one of the JavaScript reserved words. |
|||||||||||||||||||||||||||||||||||||||