HTML and CSS Reference
In-Depth Information
provides another set of objects, and the browser still more. You can
also create your own objects; let's start with that.
The simplest way to create an
object is with an object literal . An
empty object is a pair of braces.
The object can contain variables
and functions, but when they're
part of an object they're referred
to as properties and methods.
In JavaScript, you can access a
property or method on an object
by using a period ( . ) followed by a
label. You can create properties
and methods by assigning a value,
as shown here.
This is the same code in an easier-to-read format:
var myObject = {};
myObject.myProperty = 2;
myObject.myMethod = function(n) {
return n * 3;
You can then call the method, passing in the property like this:
Now that you have an object to play with, it's time to learn about the
final type of loop: . The following screenshot of the console
shows a loop in action on the myObject object just created.
Search WWH ::

Custom Search