HTML and CSS Reference
In-Depth Information
EXPLANATION ( CONTINUED )
4
The property this.backpage is assigned the name of the function, pageBackward ,
that will serve as the object's method.
5
The function pageForward() is defined. Its purpose is to increase the page number
of the topic by one , and return the new page number.
6
The function pageBackward() is defined. Its purpose is to decrease the page num-
ber by one and return the new page number.
7
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
publisher.
8
The pagenumber property is set to 5 .
9
The properties of the object are displayed in the browser window.
10
The for loop is entered. It will loop three times.
11
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.
12
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.
8.2.3 Inline Functions as 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
 
 
Search WWH ::




Custom Search