HTML and CSS Reference
EXPLANATION ( CONTINUED )
The property this.backpage is assigned the name of the function, pageBackward ,
that will serve as the object's method.
The function pageForward() is defined. Its purpose is to increase the page number
of the topic by one , and return the new page number.
The function pageBackward() is defined. Its purpose is to decrease the page num-
ber by one and return the new page number.
A new object called myBook is created. The new operator invokes the Book() con-
structor function with three arguments: the title of the topic, the author, and the
The pagenumber property is set to 5 .
The properties of the object are displayed in the browser window.
The for loop is entered. It will loop three times.
The uppage() method is called for the myBook object. It will increase the page
number by 1 and display the new value, each time through the for loop.
The backpage() method is called for the myBook object. It will decrease the page
number by 1 and display the new value each time through the loop. The output
is shown in Figure 8.6.
Figure 8.6 An instance of the Book class, its properties, and methods.
Rather than naming a function outside the class, an inline or anonymous function can
be assigned directly to a property within the constructor function. (Every instance of the