• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 11. Manipulating Information > Building Custom Classes with Functions

Building Custom Classes with Functions

You can use functions not only to perform certain tasks, such as those in the previous examples, but also to define the properties and methods of new classes. This lets you organize and customize information in your scripts for easier access and storage and to save memory by consolidating your scripts. Using a constructor function (the operator new plus the name of your function) lets you instantiate an object of a custom class. For example, consider the function:

function Scores (player1, player2) {

this.player1Score = player1;

this.player2Score = player2;

}


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint