Object-Oriented JavaScript






Object-Oriented JavaScript

Object-oriented JavaScript is essential when building large-scale Ajax applications. This approach to programming lends reusability, scalability, and flexibility to our applications. Object-oriented approaches provide a blueprint for object reusability, which ultimately tends to minimize the amount and duplication of code in our applications. Minimizing the amount and duplication of code not only helps us build an application faster, but it also makes updates and management a simple chore for developers. When approaching your application in an object-oriented way, there is some planning that is involved to make sure that your objects are reusable now and, in the mapped future, to lend scalability for any additions and/or updates to the application. Creating these objects may sometimes seem like overkill if a developer thinks she can just knock out an application in a short amount of time, which is frequently the case. However, by beginning to approach all of our applications in this way, we will be conditioned to think of applications in a new lightfrom more of an engineer's perspectiveand we will automatically begin to approach and build them in a better way. This allows us to use our objects in other applications and reuse code in ways that will speed up our development time immensely.

This chapter may not be the most glamorous, and you may be wondering why you would need to understand object-oriented programming (OOP) concepts with JavaScript in order to create Ajax applications. The use of JavaScript objects in your Ajax applications makes it very simple to manipulate data and create graphical user interface (GUI) elements that can be ported from one application to the next. This allows you to put more time into the planning, engineering, and development of the site or, hopefully, even the development of new Ajax components, rather than rewriting the same code in each of your applications or, as they say, "reinventing the wheel." With that said, understanding the creation of these different object types is essential to creating custom objects, components, and even libraries of our own.

Unlike other programming or scripting languages, there are many ways to create objects with JavaScript. Although this book will primarily use prototypes as the object-oriented approach of choice, we will also cover object constructors in this chapter. Object constructors are valid and useful ways to create objects and translate rather seamlessly into our sample application. You can use this approach in the book sample or in your future Ajax applicationsthe choice is yours.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows