Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


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

Part I: Core JavaScript > Classes, Constructors, and Prototypes

Chapter 9. Classes, Constructors, and Prototypes

JavaScript objects were introduced in Chapter 7. That chapter treated each object as a unique set of properties, different from every other object. In many object-oriented programming languages, it is possible to define a class of objects and then create individual objects that are instances of that class. You might define a class named Complex to represent and perform arithmetic on complex numbers, for example. A Complex object would represent a single complex number and would be an instance of that class.

JavaScript does not support true classes the way that languages like Java, C++, and C# do.[*] Still, however, it is possible to define pseudoclasses in JavaScript. The tools for doing this are constructor functions and prototype objects. This chapter explains constructors and prototypes and includes examples of several JavaScript pseudo-classes and even pseudosubclasses.

[*] True classes are planned for JavaScript 2.0, however.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial